Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:18:21+00:00 2026-06-18T11:18:21+00:00

I’ve asked this question before, but have changed my code since. I’m having trouble

  • 0

I’ve asked this question before, but have changed my code since. I’m having trouble with this script which inserts form data into a table. The first insert creates a booking which stores the customer’s contact details. The second insert takes the booking ref created in the first and creates a ‘JOB’ for the customer. The final insert is supposed to create a second ‘JOB’, the customer’s return journey.

The first two inserts are running fine,
but it ignored the final one, the second JOB insert.

I have checked the table structures, and the data been passed to the script everything is okay, so the problem must be in the script (shown below) any help is greatly appreciated.

Is it correct to use one script to insert into the same table twice?

<?php

  $customer_title           =  $_POST['customer_title'];
  $customer_first_name      =  $_POST['customer_first_name'];
  $customer_last_name       =  $_POST['customer_last_name'];
  $billing_address          =  $_POST['billing_address'];
  $customer_tel             =  $_POST['customer_tel'];
  $customer_mobile          =  $_POST['customer_mobile'];
  $customer_email           =  $_POST['customer_email'];
  $passengers               =  $_POST['passengers'];
  $cases                    =  $_POST['cases'];
  $return_flight_number     =  $_POST['return_flight_number'];
  $price                    =  $_POST['price'];
  $pickup_date              =  $_POST['pickup_date'];
  $pickup_time              =  $_POST['pickup_time'];
  $pickup_address           =  $_POST['pickup_address'];
  $destination_address      =  $_POST['pickup_destination'];
  $return_date              =  $_POST['return_date'];
  $return_time              =  $_POST['return_time'];
  $return_pickup            =  $_POST['return_pickup'];
  $return_destination       =  $_POST['return_destination'];
  $booking_notes            =  $_POST['booking_notes'];

  $booking_status           =  "Confirmed";
  $authorised               =  "N";

  $booking_agent            =   "ROOT_TEST";
  $booking_date             =   date("Y/m/d");

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

  $scheduled   = "N";

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

  $create_job->execute(array(
      ":booking_ref"          =>  $booking_ref,
      ":pickup_date"          =>  $pickup_date,
      ":pickup_time"          =>  $pickup_time,
      ":pickup_address"       =>  $pickup_address,
      ":destination_address"  =>  $destination_address,
      ":scheduled"            =>  $scheduled  
  ));



  $return = "Y";


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

  $create_return->execute(array(
      ":booking_ref"          =>  $booking_ref,
      ":pickup_date"          =>  $return_date,
      ":pickup_time"          =>  $return_time,
      ":pickup_address"       =>  $return_pickup,
      ":destination_address"  =>  $return_destination,
      ":scheduled"            =>  $scheduled,
      ":return"               =>  $return
  ));




}


?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:18:22+00:00Added an answer on June 18, 2026 at 11:18 am

    It is incorrect for sure, as inserting the same data twice violates one of most important database architecture laws – Database Normalization principle

    However, there is no technical issues with it. There is some mistake which you have to catch using the error message from mysql. To have it, add this line after connecting to PDO.

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    

    Please note that catching the actual error is the only way to debug SQL queries. Just watching the code makes no sense nor help.

    return must be a mysql keyword. write it as

    `return`
    

    By the way, I can’t stand such enormously huge code.

    If I were you, I’d make it in 10 lines, not 50:

    $allowed = array('customer_name', 'billing_address', 'contact_tel', 'contact_mob',
                     'contact_email', 'party_pax', 'party_cases', 'booking_notes', 'price'); 
    $insert = $db->filterArray($_POST,$allowed);
    
    $insert['booking_status'] =  "Confirmed";
    $insert['authorised']     =  "N";
    $insert['booking_agent']  =   "ROOT_TEST";
    $insert['booking_date']   =   date("Y-m-d");
    
    $db->query("INSERT INTO bookings SET ?u", $insert);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.