php
One PHP Script with two PDO queries?
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" )); }
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 )");
Related Links
Error running 'composer install' on cpanel server using PuTTY
Exclude laravel route using wildcard
how can i get domain expiration date and used disk space in server using php? [duplicate]
Searching my Array for values containing a specific character
How to increase wocommerce product variation?
Split Order ID's on single checkout
Doctrine array field with default value
Twilio create address subaccount issue api php
Delete multiple records with different identifiers from a large table without using loop mysql php
Need to remove zero's from html table
How can I get the time of a remote server?
How can I show my image in codeigniter base_url
Laravel redirects to login on every page even after logging in
PHPExcel - Delete rows with 0 in a specific column
How to use mysql_field_len in PHP 7?
PHP web scraping - return content after javscript loads