我正在尝试在PHP中使用测验程序。到目前为止,我在编写任何代码时都没有遇到什么问题。但是,这一次,我似乎无法将字符串传递给表单的下一页。基本思想是琐事计划。检索随机问题,用户回答问题,程序检查答案是否正确。最终,该计划将保持得分,但我还没有那么远,因为我似乎无法检查对这个问题的答案。我无法弄清楚我哪里出错了。
如果对此有答案,我很抱歉,我错过了。我看到的唯一一件事就是使用Javascript,这超出了我目前的技能。感谢。
守则:
<!DOCTYPE html>
<html lang="en-US">
<head>
<!--link-->
<meta charset="UTF-8" />
<title>Sports Trivia</title>
</head>
<body>
<form>
<?php>
extract($_REQUEST);
include("triviaQuestions.php");
//functions
//Display Next Question template provided by Dan Brekke
function nextQuestion($trivia,&$used)
{
do
$num = rand(0,count($trivia)-1);
while ($used[$num]);
$used[$num] = true;
reset($trivia);
for ($i = 0; $i < $num; $i++)
next($trivia);
return key($trivia);
}
function displayQuestion($trivia,$count,&$used,$question)
{
if ($count < count($trivia))
{
$questionNum = $count+1;
echo <<< HERE
<h3>Question $questionNum:</h3>
<h3>$question</h3>
HERE;
}
else
$question = "You've reached the endzone!";
}
function displayButtons()
{
echo <<< HERE
<p>
<input type="submit" name="button" value="Next Question" />
<input type="submit" name="button" value="Quit" />
</p>
HERE;
}
function passData($trivia,$count,$used)
{
echo "<input type='hidden' name='count' value='$count'>";
for ($i = 0; $i < count($trivia); $i++)
echo "<input type='hidden' name='used[$i]' value='$used[$i]'>";
}
if ($button == NULL || $button == "New Game")
{
//variables
$used = NULL;
$count = 0;
$correct = 0;
echo <<< HERE
<h1>Sports Trivia!</h1>
<h3>Welcome to Sports Trivia. Enter your name and click Play to begin!</h3>
<h3>Name:
<input type="text" name="name" autocomplete="off" autofocus="on">
</h3>
<input type="submit" name="button" value="Play" />
<input type="submit" name="button" value="Display Scores" />
<br /><br />
<a href="..">Back To Home</a>
HERE;
//experimenting, since I don't know how this works
serialize($trivia);
serialize($used);
}
else
{
if ($button == "Play")
{
$question = nextQuestion($trivia,$used);
displayQuestion($trivia,$count,$used,$question);
echo <<< HERE
<input type="text" name="answer" autocomplete="off" autofocus="on" />
<p>
<input type="submit" name="button" value="Enter" />
</p>
HERE;
}
else if ($button == "Enter")
{
echo $question;
}
}
echo <<< HERE
<input type="hidden" name=$helloWorld />
HERE;
?>
</form>
</body>
</html>