below is my php code, $db is connection to db
<?php
if (! hasEmpty([$_POST['loc-city']])) {
$city = htmlspecialchars_decode($_POST['loc-city']);
$addr = htmlspecialchars_decode($_POST['loc-address']);
$prov = htmlspecialchars_decode($_POST['loc-province']);
$pos = htmlspecialchars_decode($_POST['loc-poscode']);
$houseID = mysqli_insert_id($db);
$sql = "INSERT INTO house (houseID, username, houseStatus) VALUES ('".$houseID."', '".$_SESSION['login_user']."','0')";
$sql2 = "INSERT INTO house_loc (houseID, city, address, province, postalCode) VALUES ('".$houseID."',?,?,?,?)";
$query = $db->prepare($sql);
$query2 = $db->prepare($sql2);
$query2->bind_param('ssss',$city,$addr,$prov,$pos);
if (!$query->execute()) {
echo '{"status":"error", "errorMsg" : "Error!"}';
exit;
}
if (!$query2->execute()) {
echo '{"status":"error", "errorMsg" : "Error!"}';
exit;
}
echo '{"status":"success"}';
?>
I am having issue with inserting both statements to the database, I tried changing $houseID directly to an int and it works, so I think the problem occured at
$houseID = mysqli_insert_id($db);
as it cannot be used twice?