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

Categories

HOME
openshift
apple-push-notifications
paypal-ipn
initialization
openlayers-3
yql
portable-class-library
tibco
share
repair
ag-grid
cisco
reportviewer
yeoman-generator-angular
fireloop
nsstring
game-maker
gmp
infrared
home
weex
kaggle
altium-designer
candlestick-chart
ava
chronicle-queue
firemonkey-style
raima
fstar
spreadsheetgear
msdeploy
jackrabbit-oak
sfml
credit-card
wampsharp
knights-tour
android-collapsingtoolbar
polyml
xerces-c
aurelia-cli
ms-dos
hidden-markov-models
stat
get-event-store
oauth2-playground
expandablelistview
type-inference
xcode8.2
autorelease
non-linear-regression
datediff
skip-lists
pen
asp.net-web-api-routing
word-2007
mobile-angular-ui
clrs
mechanicalturk
business-rules
rustdoc
d3v4
finder
oid
nsrunloop
carmen
seccomp
dojo-build
groovyfx
right-to-left
gnucash
noclassdeffounderror
uibinder
simian
exists
jeasyui
distributed-cache
vimperator
preferenceactivity
pack
cortana
miniconda
astropy
ora-04091
ambiguity
actionpack
wicked-gem
innerhtml
mgwt
nsmutabledata
fasterxml
datagridcomboboxcolumn
adwords-apiv201402
jquery-mobile-flipswitch
category-theory
code-complexity
hyperloglog
xulrunner
jack
gpu-programming
proxy-server
application-blocks
illuminate-container
tnt4j
ax
web-frameworks
ofstream
icenium
multiscaleimage
platform-independent
sigar
nsrangeexception
canonicalization
servlet-container
nsconnection
mongrel
ppc
autobench
watchpoint
levels
html-generation
community-server
error-detection

Resources

Encrypt Message