I have made an insert and update multi_query with the code below. When I submit the form both actions execute and alert that it was successful - looking in PHPMyAdmin I can confirm that it has been inserted and updated. However, it then tells me that that the query couldn't be executed php client output.
if(isset($_POST['submit']) && isset($_POST['partno']) !== "") {
$date = date('Y-m-d');
$partNumber = $_POST['partno'];
$checkedIn = $_POST['checkedin'];
$amountReceived = $_POST['amountreceived'];
$stockQuantity = $_POST['stockquantity'];
$location = $_POST['stocklocation'];
$checkBox = ($_POST['selectGoods']) ? 1:0;
$insert = "UPDATE part SET InventoryOnHand = '".$stockQuantity."' WHERE OurPartNo = '".$partNumber."'; ";
$insert .= "INSERT INTO goods_received (Date, PartNumber, AmountReceived, Who, Location, Received) VALUES ('$date', '$partNumber', '$amountReceived', '$checkedIn', '$location', '$checkBox')";
if (mysqli_multi_query($con, $insert)){
echo '<script>alert("Insert Successful")</script>';
} else{
echo '<script>alert("Tom Is a Idiot and this is not working")</script>';
}
var_dump($insert);
}
Copy for the var_dump and the execute issue:
string(212) "UPDATE part SET InventoryOnHand = '10' WHERE OurPartNo = 'FK06-P'; INSERT INTO goods_received (Date, PartNumber, AmountReceived, Who, Location, Received) VALUES ('2021-04-13', 'FK06-P', '1', 'TOm222', 'GF1', '0')"
Couldn't execute query. Commands out of sync; you can't run this command now
I have already tried:
$insert = "UPDATE part SET InventoryOnHand = '".$stockQuantity."' WHERE OurPartNo = '".$partNumber."'; ";
mysqli_store_result($insert);
$insert .= "INSERT INTO goods_received (Date, PartNumber, AmountReceived, Who, Location, Received) VALUES ('$date', '$partNumber', '$amountReceived', '$checkedIn', '$location', '$checkBox')";
mysqli_use_result($insert);