I have a method that inserts multiple mass dates and times into a database. I have checked to make sure that the method is receiving the array of masses correctly. The array it receives takes the following structure:
array(2) {
[0]=> array(3) {
[“mass_name”]=> string(13) “Barry\'s Mass”
[“mass_date_time”]=> string(19) “2012-04-22 16:00:00”
[“mass_private_public”]=> string(6) “public”
}
[1]=> array(3) {
[“mass_name”]=> string(14) “Jaclyn\'s Mass”
[“mass_date_time”]=> string(19) “2012-04-22 16:00:00”
[“mass_private_public”]=> string(6) “public”
}
}
Here is the PHP used to INSERT into the database.
public function Set_add_masses($set_masses) {
global $mysqli;
if ($stmt = $mysqli->prepare("INSERT INTO masses (mass_name, mass_date_time, mass_private_public, user_edited) VALUES (?, ?, ?, ?)")) {
foreach ($set_masses as $key => $value) {
$stmt->bind_param("sssi", $set_masses[$key]['mass_name'], $set_masses[$key]['mass_date_time'], $set_masses[$key]['mass_private_public'], $_SESSION['user_id']);
if ($stmt->execute()) {
$this->masses = 'Success';
} else {
$this->masses = 'Failed at INSERT ' . $key;
break;
}
}
$stmt->close();
} else {
$this->masses = NULL;
}
return $this->masses;
}
When I dump the $this->masses variable, I get “NULL” and the masses aren’t inserted into the database. Any ideas?