Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

PHP insert queries with PDO

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...