Hello PHPFreaks forum,
I am strugging to figure out, how to create a button that stops the rand problem generation and output the users score of correct answers. Right now it only checks if the answers are right and says correct or if its wrong it display the correct answer.
I was thinking i need to turn my random varibles into $_SESSION variables, so it stores the users data and then i can echo it back to the user. I am not sure how to this can you please help me. I have been working on this for week now and i am stuck!
<html>
<head>
<?php
session_start()
?>
<title>Second Grade Math quiz</title>
</head>
<body id="body">
<div id="wrapper">
<div id="header">Mutiple:</div>
<div id="quizbox">
<?php
$value1 = rand (1,10);
$value2 = rand (1,20);
?>
<form action="mathq.php" method="post">
<input type="text" name="input1a" value="<?php echo $value1; ?>" class="value" />
<input type="text" value="x" class="equa" />
<input type="text" name="input2a" value="<?php echo $value2; ?>" class="value" />
<input type="text" value="=" class="equa" />
<input id="answer" type="text" name="answer" value="" class="answer" /><br /><br />
<input type="submit" value="Submit answer" class="submit">
<INPUT TYPE="RESET" VALUE="Clear all fields of this form">
</form>
<?php
if(isset($_POST['input1a']) && isset($_POST['input2a']) && isset($_POST['answer'])) {
$result = $_POST['answer'];
$input1a = $_POST['input1a'];
$input2a = $_POST['input2a'];
if (!empty($input1a) && !empty ($input2a) && !empty($result)) {
//echo '<span class="success">Success! ';
}
if ($result == $input1a * $input2a)
{
print($input1a . ' x ' . $input2a . ' = ' . '<span class="correct">' . $result . '</span>' . '<br />Correct!');
}
else
{
print($input1a . ' x ' . $input2a . ' = ' . '<span class="incorrect">' . $result . '</span>' . '<br />Wrong!<br /> The correct answer was: ' . '<span class="correct">' . $input1a * $input2a . '</span>');
}
}
?>
</div>
</div>
</body>
</html>











