I have a form and script which is supposed to insert multiple records (MOT dates and readings) for a car with a specific ID.
I use this code to output a number of rows in the form:
$output = "";
$desired_row_count = 20;
for ($i=0; $i<$desired_row_count; $i++) {
$output .= ' <div class="addnewcar-wide"><label for="_MotDate">Date</label><input name="_MotDate['.$i.']" type="text"
size="10" /><label for="_MotOdometer">Odometer</label><input name="_MotOdometer['.$i.']" type="text" size="20" /></div>';
}
echo $output;
This works fine in that it outputs the rows.
Then in the form handler script:
$motdate = $mysqli->real_escape_string($_POST['_CarID']);
$motdate = $mysqli->real_escape_string($_POST['_MotDate']);
$motodometer = $mysqli->real_escape_string($_POST['_MotOdometer']);
// loop through motDate array and add to INSERT statement
for ($i=0; $i<count($motdate); $i++) {
if ($motdate[$i]!="" && $motodometer[$i]!="") {
$addmotdetails = $mysqli->query('INSERT INTO mothistorytable (`carid`,`motdate`,`motodometer`) VALUES ('.$carid.',"'.
$motdate[$i].'","'.$motodometer[$i].'")');
}
}
If I echo $addmotdetails it doesn’t show anything, so the data clearly isn’t coming through at all. I checked the database
table and the records aren’t being added. Guess I’m missing something but the process doesn’t show any errors so I’ve no idea
why it’s not working. Any ideas?
Thanks