php - 输入字段有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
打印正确
解决方案
推荐阅读
- excel - 计算多个范围的平均值
- flutter - 有没有办法让 Flutter macOS 应用的字符选择栏出现在正确的位置?
- vuejs2 - Vue.js (v.2) 仅在单击按钮后加载(获取)数据
- r - 条件均值和散点图
- r - 如何在预期时使用 testthat 将消息和警告静音
- java - Java Streams 验证是否只有一个结果
- php - 在 Woocommerce 结帐页面中显示自定义消息
- php - laravel 在给定 id 与连接表 id 不匹配时获取数据
- python - 使用 R 中的网状包,Python 输出未在 html 中显示
- javascript - 使用类扩展数据属性功能