0

我最近开始在重建客户的出租车预订系统时使用 PDO。

我有一个名为 create_booking.php 的脚本,它最初将预订详细信息插入 MySQL 数据库中的预订表中。插入客户详细信息后,它会检索 lastinsertID 以获取预订参考。然后它在作业表中创建一个作业并引用预订参考来关联作业/预订。

第一个插入工作正常,但第二个插入不是 . 有任何想法吗?

    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"

    ));

}
4

1 回答 1

2

您的第二个 SQL 查询丢失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 )");

于 2013-01-20T16:48:53.247 回答