I’m new at PHP and am stuck trying to insert data from two arrays into one mysql table.
The Table stores following fields: date, case_id, statusid
case_id would be the same for all records inserted in one statement and the value comes from a session variable.
the date array and status_id array are both being posted from a form; I know both arrays are posting fine because I’ve used a for each loop to insert both arrays to the table individually.
Any help will be much appreciated. I’ve left the foreach condition empty for suggestions.
$caseid = mysqli_real_escape_string($link, $_SESSION['caseid']);
$status = $_POST['statuses'];
$date = $_POST['dates'];
foreach() {
$sql = " INSERT INTO casestatus (date, case_id, statusid) VALUE
('$date', '$caseid', '$statusid') ";
if (!mysqli_query($link, $sql)) {
$error = 'Error assigning selected statuses to case.';
include 'error.php';
exit();
}
}
Try this.
Don’t forget to replace
VALUEwithVALUESin your INSERT statement.