Using the code below, I am auto-incrementing an ID value as a primary key in the constant_client table, which then needs to be used as a foreign key in the varying_client table. The first prepared statement works correctly, and the $id variable which is set to $conn->insert_id also appears to work, as when echoing the statement I am getting the correct incremented value from the first table. However, when attempting the second query, I am getting a "Call to a member function bind_param() on bool" error.
$stmt = $conn->prepare("INSERT INTO constant_client (on_programme, last_name, first_name, middle_name,
date_birth, gender, ohs, maiden_name, marital_status, ethnicity, height, weight, hair_colour,
eye_colour, tattoos, features, chronic, disabilities)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("isssssisssssssssss", $on_programme, $last_name, $first_name, $middle_name, $date_birth,
$gender, $ohs, $maiden_name, $marital_status, $ethnicity, $height, $weight, $hair_colour,
$eye_colour, $tattoos, $features, $chronic, $disabilities);
$stmt->execute();
$id = $conn->insert_id;
echo $id;
$stmt = $conn->prepare("INSERT INTO varying_client (id, address, suburb, postcode, state, client_phone, client_mobile
emergency_contact, emergency_phone)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param('issisiisi', $id, $address, $suburb, $postcode, $state, $client_phone, $client_mobile,
$emergency_contact, $emergency_phone);
$stmt->execute();
$conn->close();
I'm very new to prepared statements, so it is entirely possible that I am messing up the syntax somewhere, but if anyone could shed some light on it it would be much appreciated.