首页 > 解决方案 > 输入字段有php数组但不记录第一个元素

问题描述

在表单中有简单的输入字段,我在其中收集问题的答案,因此名称是一个数组;但是当我发布表格时,发布的内容是错误的

<form name='getanswers' method = 'POST' action = 'DQSaveAnswers.php/'>
<? for($i=0; $i<3 ; $i++) { ?>
<tr>
<td><?echo $question[$i] ;?> </td>
<td> <input type="text" name="myAnswer[]" class="myclass" id="myAnswer[]" 
> </td>
<td><?echo $qPoints[$i] ;?> </td>
<td> <input type="hidden" name ="qId[]" value="<?echo $qId[$i];?>" > 
</td>
<td> <input type="hidden" name ="question[]" value="<?echo 
$question[$i];?>"></td>
</tr>
<? } ?>

这是简单的代码 - 我打印 3 个问题(来自 db);在该输入字段旁边以捕获用户答案等。当我在 DQsqveAnswers.php 中打印“myAnswer[]”和“qId[]”时,我得到了 qId[] 的正确结果,但没有得到 myAnswer[] 的正确结果。这就是我在 DQSaveAnswers.php 中的内容

$answers = array();
$qId = array();
$answers=$_POST['myAnswer'];
$question=$_POST['question'];
$qId=$_POST['qId'];

echo "id are ";
print_r($qId);
echo "answers are ";
print_r($answers);
echo " and questions are ".print_r($question);

作为用户,我输入值“RR”,“dc”,1

我打印的输出是 id 是

Array ( [0] => 1 [1] => 2 [2] => 3 )

答案是

Array ( [0] => dc [1] => 1 )

Array ( [0] => who will win today(Match1) 
        [1] => who will be the man of the match(Match1- pl copy/paste from list below) 
        [2] => how many sixers will be hit(Match1) 
      )

检查“答案是”之后的内容...只有两个值也不正确,第一个值 RR 被遗漏了..不确定出了什么问题,因为$qId打印正确

标签: phphtml

解决方案


推荐阅读