我正在嘗試創建一個數學測驗頁面。第一頁需要生成一個顯示爲標題的問題,該問題詢問用戶將兩個隨機數相乘在一起。 然後根據用戶的輸入,將它們帶到不同的頁面。 如果它們正確,則顯示段落「你是對的!」。 如果他們錯了,它會顯示段落「你是不正確的」,並邀請用戶再試一次。 ,如果他們輸入字符串,則會顯示段落「我不明白您的回覆」,並邀請用戶再次嘗試。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