我正在尝试创建一个数学测验页面。第一页需要生成一个显示为标题的问题,该问题询问用户将两个随机数相乘在一起。 然后根据用户的输入,将它们带到不同的页面。 如果它们正确,则显示段落“你是对的!”。 如果他们错了,它会显示段落“你是不正确的”,并邀请用户再试一次。 ,如果他们输入字符串,则会显示段落“我不明白您的回复”,并邀请用户再次尝试。PHP简单的数学测验程序
到目前为止,我有下面的代码,布局是正确的,但标题不工作,我试图显示一个新的页面,但他们再次没有加载。任何人都知道我要去哪里错了?
<?php
$first = Rand(1,10);
$second = Rand(1,10);
echo <h1>"What is " . $first . "times " . $second . "?"</h1>;
if(is_int($_POST['answer']) == 1){
if($_POST['first']*$_POST['second'] == $_POST['answer']){
header("Location: correct.html");
exit();
}
else{
header("Location: incorrect.html");
exit();
}
}
else if(is_string($_POST['answer']) == 1) {
header("Location: response.html");
exit();
}
?>
<!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['file:///X|/Software Development/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>
这是因为您要在执行位置重定向之前将数据发送到标头。 (提示,移动你的'echo') – Ohgodwhy
你没有看到警告吗?如果没有,启用它们。 –
@Ohgodwhy ack,没有看到你的评论。 – mellowfish