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 6893761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:41:56+00:00 2026-05-27T06:41:56+00:00

I try to retrieve the latest added bookingID from table booking but I do

  • 0

I try to retrieve the latest added bookingID from table booking but I do not know how to get it.
The scenario: when user click ‘submit’ button, mysql query will generate a parentBookID and store userID, eventID in table booking.Then query will get the created parentBookID to insert into table bookingDetail, user will make multiple bookings and these detail will store in table bookingDetail with same parentBookID.

The problem is, I do not know to get the current parentBookID to be store in table bookingDetail from table booking.

<?php

session_start();


if ( !isset($_SESSION['AUTHORIZED_USERNAME']) || empty($_SESSION['AUTHORIZED_USERNAME']) )  {
header("location:index.php");
}else{
$user=$_SESSION['AUTHORIZED_USERNAME'];
$userID= $_SESSION['AUTHORIZED_CUSTNO'];
$event=$_SESSION['EVENT_ID'];
 include('db.php');

 //check submitted totalDay
 if (isset($_POST['submit']) && isset($_POST['totalDay'])) {


//insert parentBookingID
$parent=mysql_query("INSERT into booking (custNo, eventID,dateBook) VALUES ('$userID','$event',NOW())");

//no logic
$queryParent="SELECT parentBookID from booking where custNo='$userID' and eventID='$event'";
$queryParentResult=mysql_query($queryParent);
while($parentBook = mysql_fetch_array($queryParentResult)){
    $parentBookID=$parentBook['parentBookID'];

$totalDay=$_POST['totalDay'];
$allBooth="";


foreach ($totalDay as $d) {

    echo $d;

    $bookingInfo  = $d;
    $bookingInfo = explode(" ", $bookingInfo);
    echo $bookingInfo[0]; // boothAlias
    echo $bookingInfo[1]; // boothID
    echo $bookingInfo[2]; // day



    $result = mysql_query("SELECT * FROM bookingDetail WHERE boothID='$bookingInfo[1]' and day='$bookingInfo[2]' and username='$user'");

    $num_rows = mysql_num_rows($result);

        if ($num_rows) {
            echo "Exist";
        }else{

    $str = "INSERT INTO bookingDetail (username, custNo, eventID, date, day, boothAlias, boothID, parentBookID) VALUES ('$user', '$userID','$event',NOW(),'$bookingInfo[2]','$bookingInfo[0]','$bookingInfo[1]','$parentBookID');";
    $res = mysql_query($str);

    if($res)
            echo 'Success';
    else
            echo 'Failure';

    $allBooth= substr($allBooth, 0, -2); 

echo "<p>Booth(s): <strong>$allBooth</strong>&nbsp;<strong>$user</strong>&nbsp;<strong>$event</strong><strong>$userID</strong></p>\r\n";

    }
}
    }

    header("refresh:5;url=mybooking.php");
echo "<img src='loading16.gif' style='margin-top:8px; float:left'/>";
echo 'You\'ll be redirected in about 5 secs. If not, click <a href="mybooking.php">here</a>.';  

}else{

echo "You do not make any booking";
    header("refresh:5;url=booking2.php");
    echo "<img src='loading16.gif' style='margin-top:8px; float:left'/>";
    echo 'You\'ll be redirected in about 5 secs. If not, click <a href="booking2.php">here</a>.';   
}

?>
  • 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-05-27T06:41:57+00:00Added an answer on May 27, 2026 at 6:41 am

    Assuming you have an AUTO_INCREMENT column in booking, you could use mysql_insert_id(); to get it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to retrieve data from dbpedia but I get error every time i
i try to retrieve data but i think i'm not good at sql query.
I get an error when I try to retrieve from SQLite into an Array.
I try to retrieve all database records from Tournament which belongs to User. $cond
I try to retrieve a array from one table What is wrong with this
I am adding string[] into Arraylist, But when i try to retrieve value from
I am currently try to retrieve a latitude and longitude value from a location.
I get a Data type mismatch criteria expression error when i try to retrieve
my table column is: AttachContent varbinary (max) when i try to retrieve the data
I try to retrieve HTML data from my database and display them in a

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.