我正在做一个简短的测验,我想知道我怎样才能把测验的答案传递到下一页?
My Quiz page
<?php
$qtspool =
array( 1=> array('qts'=>'What is my name?', 'ans'=>'Lu'),
2=> array('qts'=>'What is the module code?', 'ans'=>'307'),
3=> array('qts'=>'What is missing char abde?', 'ans'=>'c'),
4=> array('qts'=>'What is missing number 1345?', 'ans'=>'2')
);
$qtspick_key = array_rand($qtspool,3);
for ($i=0; $i<3; $i++)
{
$qtspick_key[$i];
}
$pickqts = array();
$i = 0;
foreach ($qtspick_key as $key)
{
$pickqts[$i] = $qtspool[$key];
$i++;
}
?>
<form method="get" action="abc.php" >
<br>
<?php
foreach($pickqts as $qtsno=>$value)
{
?>
<?php echo $value['qts']; ?>
<input name="user_ans" type="text" >
<input type="hidden" name="answers" value="<?php echo htmlspecialchars($value['ans']); ?>" />
<br>
<?php
}
?>
<input type="submit"/>
</form>
我尝试了<input type="hidden" name="answers" value="<?php echo htmlspecialchars($value['ans']); ?>" />
,但它只能将问题的最后一个答案传递到下一页。
p。S:当我做echo $value['ans'];
时,我可以返回测试页面上随机问题的所有答案。
您必须通过数组发送变量,因此更改行:
<input name="user_ans" type="text" >
<input type="hidden" name="answers" value="<?php echo htmlspecialchars($value['ans']); ?>" />
:
<input name="user_ans[]" type="text" >
<input type="hidden" name="answers[]" value="<?php echo htmlspecialchars($value['ans']); ?>" />