I have some php variables that capture multiple data in the form of an array and i want to input these values in a mysql table.
$surname = unserialize(base64_decode($_POST['surname']));
$firstname = unserialize(base64_decode($_POST['firstname']));
$othername = unserialize(base64_decode($_POST['othername']));
$dob = unserialize(base64_decode($_POST['dob']));
$gender = unserialize(base64_decode($_POST['gender']));
$email = unserialize(base64_decode($_POST['email']));
$phone = unserialize(base64_decode($_POST['phone']));
$location = unserialize(base64_decode($_POST['location']));
$stmt = $connQlife->prepare("INSERT INTO cimbooking (surname, firstname, othername, dob, gender, email, phone, location) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
foreach($surname as $key=>$sname){
$stmt->bind_param('ssssssss', $sname, $firstname[$key], $othername[$key], $dob[$key], $gender[$key], $email[$key], $phone[$key], $location[$key]);
$stmt->execute();
}
$stmt->close();
What happens when this runs is what i can't seem to understand. Looking at the code, this should work just fine. Now in a scenario where the number of records is supposed to be 3, I should see 3 records in the table after submission, but only the first record is being entered into the mysql table. Furthermore, on troubleshooting, i find that when the code runs, the first record that enters the table occupies say id 1. If i refresh the page so the code runs again, the first record of that new command occupies id 4 and not id 2 like it should be. (The id field in the database is already set to auto increment).
Which seems to me like when one record enters the table, the other records enter and disappear or something. I don't seem to understand why.