<html>
<head><title></title></head>
<body>
<?php
if (isset ($_POST['posted'])) {
if ($_POST['question1'] == "Lisbon") {
echo "You are correct, $_POST[question1] is the right answer<hr>";
}
if ($_POST['question1'] != "Lisbon") {
echo "You are incorrect, $_POST[question1] is not. the right answer<hr>";
}
}
?>
<form method="POST" action="quiz.php">
<input type="hidden" name="posted" value="true">
What is the capital of Portugal?
<br>
<br>
<input name=''question1" type=''radio" value=''Porto''>
Porto
<br>
<input name=''question1" type="radio" value=''Lisbon''>
Lisbon
<br>
<input name="question1" type="radio" value=''Madrid''>
Madrid
<br>
<br>
<input type=''submit''>
</form>
</body>
</html>
这是整个部分,来自PDF文件。问题是,他们没有说明为什么在if语句中使用' '表示question1,但在echo语句中没有引号。
简而言之:为什么在if语句中$_POST['question1']有' ', 而在echo语句中$_POST[question1]没有。它们是同一个变量。 谢谢。
''
(两个单引号)而不是"
(一个双引号)。不确定这只是你发布时的错误还是实际代码中的错误,但你可能需要检查一下。 - Wesley Murch