I get an error/notice like: Undefined offset: 0
I know the problem is my array, but i have no idea to fix it.. so i need your help :/
I have a form in a jquery datatables, where the data comes from mysql. the form looks like this example:
+-----+-------+----------------------+
| no. | name | visitorstatus |
+-----+-------+----------------------+
| 1 | max | o private o business |
| 2 | peter | o private o business |
| 3 | lisa | o private o business |
+-----+-------+----------------------+
(the "o"´s are the radio buttons)
the form for the radio buttons are:
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>';
the form for the names is:
echo '<td><input type="checkbox" name="visitorname[]" value="' .$row->visitornameid. '"></td>';
and this is my way of insert the data into 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();
}
result: Undefined offset: 0 at line 80
:(