du22399 2013-01-20 16:44
浏览 20

一个带有两个PDO查询的PHP脚本?

I've recently starting using PDO in a rebuild of a client's taxi booking system.

I have a script called create_booking.php, which initially inserts the booking details into a bookings table in the MySQL database. After inserting the customers details it retrieves the lastinsertID to get the booking ref. It then creates a job in the jobs table and references the booking reference to relate the job/booking.

The first insert is working fine, but the second insert isn't . Any ideas?

    if (isset($_POST['customer_title'])) {

  include('../assets/db_connection.php');

  $create_booking = $db->prepare("INSERT INTO bookings(customer_name, billing_address,    contact_tel, contact_mob, contact_email, party_pax, party_cases, booking_notes, price, booking_agent, booking_date, booking_status, authorised)
                                      VALUES(:customer_name, :billing_address, :contact_tel, :contact_mob, :contact_email, :party_pax, :party_cases, :booking_notes, :price, :booking_agent, :booking_date, :booking_status, :authorised );");
  $create_booking->execute(array(
      ":customer_name"       =>   $customer_title  . ' ' .   $customer_first_name  . ' '  .   $customer_last_name,
      ":billing_address"     =>   $billing_address,
      ":contact_tel"         =>   $customer_tel,
      ":contact_mob"         =>   $customer_mobile,
      ":contact_email"       =>   $customer_email,
      ":party_pax"           =>   $passengers,
      ":party_cases"         =>   $cases,
      ":booking_notes"       =>   $booking_notes,
      ":price"               =>   $price,
      ":booking_agent"       =>   $booking_agent,
      ":booking_date"        =>   $booking_date,
      ":booking_status"      =>   $booking_status,
      ":authorised"          =>   $authorised    
    ));

  $booking_ref = $db->lastInsertId('booking_ref'); // Takes Booking Ref generated in $create_booking

  $create_job    = $db->prepare("INSERT INTO jobs(booking_ref, pickup_date, pickup_time, pickup_address, destination_address, return, scheduled)
                                (:booking_ref, :pickup_date, :pickup_time, :pickup_address, :destination_address, :return, :scheduled )");

  $create_job->execute(array(

      ":booking_ref"          =>  $booking_ref,
      ":pickup_date"          =>  $pickup_date,
      ":pickup_time"          =>  $pickup_time,
      ":pickup_address"       =>  $pickup_address,
      ":destination_address"  =>  $pickup_destination,
      ":return"               =>  "N",
      ":scheduled"            =>  "N"

    ));

}
  • 写回答

1条回答 默认 最新

  • donglang8008 2013-01-20 16:48
    关注

    Your second SQL query is missing VALUES.

    INSERT INTO() ... VALUES()

    $create_job = $db->prepare("INSERT INTO jobs(booking_ref, pickup_date, pickup_time, pickup_address, destination_address, return, scheduled) VALUES (:booking_ref, :pickup_date, :pickup_time, :pickup_address, :destination_address, :return, :scheduled )");

    评论

报告相同问题?

悬赏问题

  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭