The code just displays a simple math question and it then checks if the typed answer is correct or not. And it works flawlessly except that I can't ever make $Answer == $Facit, whatever else I put instead of $Facit works. Ex: 9, ie if ($Answer == 9) {...
it also doesn't seem to have anything to do with local/global scope, because I can echo $Facit inside the if statements.
<div id="MainContainer">
<div class="Qt">
<?php
$num1 = rand(1,50);
$num2 = rand(1,50);
echo $num1;
echo "+";
echo $num2;
$Facit = $num1 + $num2;
?>
</div>
<form>
<input type="text" name="Answer">
<button type="submit" name="CalcAns" value="submit"> Submit Answer</button>
</form>
<?php
if (isset($_GET["CalcAns"]) != null )
{
$Answer = $_GET["Answer"];
if( $Answer == (string)$Facit)
{
echo "Correct!";
}
else if ($Answer == null)
{
echo "Type in an answer";
}
else
{
echo "Wrong";
}
}
?>
</div>