【发布时间】:2018-10-11 20:54:34
【问题描述】:
我有一个奇怪的问题,我的 PHP 测验没有检查用户提交的答案是否真的正确。我知道这一点,因为当我回答完全不正确的内容时,它仍会回复是否正确消息,并且不会实现如果答案错误则应显示的链接。起初我以为是因为我检查的是数组中的短语而不是单个单词,但在用简单的单个单词测试后,我得到了相同的结果。我对 PHP 比较陌生,一直在网上搜索,但我只找到与多项选择答案相关的答案,而不是提交文本框。这是我的代码:
数组列表:
<?php
$array['one'] = "Mickey Mouse";
$array['oneone'] = "Oswald the Lucky Rabbit";
?>
主测验页面:
<!DOCTYPE html>
<html>
<head>
<title>Final Quiz</title>
</head>
<body>
<?php
include("newquiz2.php");
print("{$array['one']} was modeled after what character created by the Disney Studio?<br>");
print("<form action='newquiz2check.php' method='get'>\n");
print("<input type='text' name='one'><br><br>\n");
print("<input type='submit' value='Submit Answer'>\n<br><br>");
print("</form>\n\n\n");
?>
</body>
</html>
测验检查:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Answers for Quiz</title>
</head>
<body>
<?php
include("newquiz2.php");
if (metaphone($one) == metaphone($oneone)) {
$one = $array['one'];
$oneone = $array['oneone'];
print("Correct: $one was modeled after $oneone");
print("<p><a href='newquiz2ask.php'>Play again </a><br><br>");
}
else{print("<a href='newquiz2ask.php'>Back to home </a><p>\n");}
?>
</body>
</html>
除此之外,其他一切都在工作。我应该使用@GET 将变量分配给数组还是什么?我不完全确定这是否是您检查提交文本框的方式。
【问题讨论】:
-
你为什么用 metaphone() 来比较,你的表单数据在哪里使用 $_GET['one'] 方法获取。实际上,您应该将问题和答案存储在具有唯一 ID 的同一数组中,这将有助于您轻松比较并实现目标。
-
这个
include("newquiz2.php");文件里还有什么?? -
@webDev 包含是使用包含数组的文件,因为它们是单独的文件,我需要能够以某种方式调用数组。至于在同一个数组中的问题和答案,具有这样的唯一 ID: $array = array( "left" => "green");
标签: php boolean boolean-logic