我收到错误/通知,如:未定义的偏移量:0
我知道问题是我的阵列,但我不知道修复它...所以我需要你的帮助:/
我在jquery数据表中有一个表单,其中的数据来自mysql。表单看起来像这个例子:
+-----+-------+----------------------+
| no. | name | visitorstatus |
+-----+-------+----------------------+
| 1 | max | o private o business |
| 2 | peter | o private o business |
| 3 | lisa | o private o business |
+-----+-------+----------------------+
(“o”是单选按钮)
单选按钮的表单是:
echo '<td><input type="radio" id="radio" name="visitorstatus['.$row->visitorid.']" value="private"> private <td>';
echo '<td><input type="radio" id="radio2" name="visitorstatus['.$row->visitorid.']" value="business"> business</td>';
名称的形式是:
echo '<td><input type="checkbox" name="visitorname[]" value="' .$row->visitornameid. '"></td>';
这是我将数据插入sql的方式:
$visitorstatus = $_POST['visitorstatus'];
$visitorname = $_POST['visitorname'];
$count_visitors = count($_POST['visitorname']);
for ($i = 0; $i < $count_visitors; $i++) {
$_visitorname = $visitorname[$i];
$_visitorstatus = $visitorstatus[$i]; //<-- this is line 80
$sql = "INSERT INTO exchange (visitorname, visitorstatus)
VALUES (
:visitorname,
:visitorstatus)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':visitorname', $_visitorname, PDO::PARAM_INT);
$stmt->bindParam(':visitorstatus', $_visitorstatus, PDO::PARAM_INT);
$stmt->execute();
}
结果:未定义的偏移量:第80行的0
:(