I am trying to use the prepared statement query to insert multiple rows in to a table. I need to retrieve 2 values from a second table and insert them along with 3 parameters.
MySQL only sees the sub query as a single value not the 2 retrieved so asks for a further parameter to be added as only four are present.
$stmt = $mysqli->prepare("INSERT INTO tbl_permit_daily_sign_off (permit_id, shift, employee_id, sign_off_date, type)
VALUES ((SELECT tbl_permit_project.permit_id, tbl_shifts.shift_name FROM tbl_permit_project
INNER JOIN tbl_shifts ON tbl_permit_project.project_id = tbl_shifts.project_id
WHERE tbl_shifts.end_time <= NOW()), ?, ?, ?)");
$stmt->bind_param("iss", $permit_employee = 0, $today, $type = "auto");
$stmt->execute();
$stmt->close();
$type = 'auto'as a parameter is irregular as far as PHP goes. That variable doesn't matter, just pass'auto'directly.