I'm trying to execute 2 queries with PDO. The first one works good, the second one doesn't update attribute status according to vehicleID = :plate. I tried to replace :plate with a real value and the query worked fine. Generally, is there any way to execute either both of queries or none of them, because now they are executed asynchronously.
<?php
//insert.php;
if(isset($_POST["item_sub_category"]))
{
include('database_connection.php');
for($count = 0; $count < count($_POST["item_sub_category"]); $count++)
{
$data = array(
':item_sub_category_id' => $_POST["item_sub_category"][$count],
':job_price' => $_POST["job_price"][$count],
':part_price' => $_POST["part_price"][$count],
':plate' => $_POST["inmember"]
);
$query = "
INSERT INTO Joblog
(description,job_price,part_price,visitID)
VALUES ((SELECT s_desc from Service where s_id=:item_sub_category_id),:job_price,:part_price,
(SELECT MAX(vis_id) from Visit WHERE vehicleID = (SELECT plate from Vehicle WHERE plate = :plate)))
";
$statement = $connect->prepare($query);
$statement->execute($data);
$query = "
UPDATE Visit SET status='Completed' WHERE vehicleID = :plate and status = 'in progress'
";
$statement = $connect->prepare($query);
$statement->execute($data);
}
echo 'ok';
}
?>
question from:
https://stackoverflow.com/questions/65892340/php-insert-queries-with-pdo 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…