Here is a simple maths quiz i've programmed but it's not displaying correctly. I want it to ask the question, then if the user responds correctly go to one webpage, if the respond incorrectly go to another. And if they enter a non numerical value to go to another webpage.
I got it to ask the question but I still haven't worked out how to display the correct webpage, but now nothing works :(
My browser says there's a problem with the line of my first if statement, but I can't see one:
<?php
$first = Rand(1,10);
$second = Rand(1,10);
if(isset($_POST['answer'])){
if(is_int($_POST['answer'])) {
if($first * $second == $_POST['answer']) {
header("Location: correct.html");
exit();
}
else {
header("Location: incorrect.html");
exit();
}
}
else {
header("Location: response.html");
exit();
}
}
else{
echo "<h1>What is " . $first . " times " . $second . "?" . "</h1>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Maths Quiz</title>
</head>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>Answer<br/>
<input type="text" id="answer" name="answer" /></p>
<p></p>
<button type="submit" name="submit" value="send">Submit</button>
<input type="hidden" name="answer" value="<?php echo $answer; ?>"/></p>
</form>
</body>
</html>