I have a PHP page that defines random variables using mt_rand() and then uses html forms to get two user inputs. And depending on whether the input numbers are equal to the randomised numbers outputs "correct".
However I have the problem that when I reload the page by submitting the values from the forms my randomised values change and the answers are always wrong. I have looked and found the solution of AJAX (J-Query function of stopping reloading). I haven't used Javascript before but will learn it if needed. My question is whether there is another way to go about getting the values and determining whether they are the same as my randomised values or will I need to stop the page from reloading upon submission?
My code is below:
<html>
<?php
$x1 = mt_rand(-12,12);
$x2 = mt_rand(-12,12);
echo "$x1<br>$x2<br>";
?>
<form action="es_algebra.php" method="POST">
<input type="number" name="x1"/>
<input type="number" name="x2"/>
<input type="submit" value="Submit"/>
</form>
<?php
if ($_POST['x1'] == $x1)
{
echo "Correct";
}
else
{
echo "Wrong";
}
?>
</html>