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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:07:06+00:00 2026-06-17T19:07:06+00:00

I have a booking system. In the MySQL database, I have a bookings table,

  • 0

I have a booking system.

In the MySQL database, I have a bookings table, that contains fields for start time and end time for any given booking in the form of hh:mm:ss. The seconds are always 00.

From my booking system, I send the times through when a new booking is being made, also in the form of start time and end time in the form of hh:mm:ss.

I need to check if the NEW booking I am trying to make does not overlap a previous booking that is already in the database.

So to start with, I will have 2 variables that contain the start and end time that was sent through POST.

$startNewBooking and $endNewBooking

so my SQL would probably start like this

SELECT * FROM bookings WHERE starttime>=$startNewBooking AND .........

Then echo error if an overlapping time was found… i.o.w if the row count > 0.

Please help me with some syntax or logic for this.

Thank You

  • 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-17T19:07:08+00:00Added an answer on June 17, 2026 at 7:07 pm

    This is my query, just edit the values as you need it

      $sql = "SELECT COUNT(*) as num FROM meeting_room_bookings
                WHERE
                (
                (startdate < start_at AND startdate > start_at)
                OR
                (startdate > start_at AND enddate < end_at)
                )
                AND
                meeting_room_id = whatever_id i was on about at the time :P";
    

    if you are going to sanitise the data then you will need to replace the startdate and enddate values with “?” and do something like this->

     $sql = "SELECT COUNT(*) as num FROM meeting_room_bookings
                WHERE
                (
                (? < start_at AND ? > start_at)
                OR
                (? > start_at AND ? < end_at)
                )
                AND
                meeting_room_id = ?";
    
        $result = p4a_db::singleton()->fetchRow($sql, array($date, $date, $date, $dateend, $merono));
    

    to go one further:

    $sql = "SELECT COUNT(*) as num FROM meeting_room_bookings
                    WHERE
                    (
                    ( start_at >= ? AND start_at <= ? )
                    OR
                    ( start_at <= ? AND end_at >= ? )
                    OR
                    ( end_at >= ? AND end_at <= ? )
                    OR
                    ( ? >= ? )
                    )
                    AND
                    meeting_room_id = ?";
    
            $result = p4a_db::singleton()->fetchRow( $sql, array( $date, $dateend, $date, $dateend, $date, $dateend, $date, $dateend, $merono ) );
    

    this method allows no dates to come within the fields outside the fields around the fields or any other possibility from that area (see diagram):

    ||       |-----------|      ||   first booking 
    |-----|                          ok
            |---|                    fails
                      |----|         fails
                 |----|               fails
    

    if you need a full explanation go to This Topic

    when you do the error messages you will need to also do if else so this syntax should do the job:

    if ( 0 == $result["num"] )
            {
                p4a_db::singleton()->query( "INSERT INTO meeting_room_bookings ( start_at, end_at, meeting_room_id, tennant_id, centre_id )
                        VALUES
                        ( ?, ?, ?, ?, ? )", array( $date, $dateend, $merono, $row['tennant_id'], $centreRow['id'] ) );
                return true;
            }
            else
            {
                P4A::singleton()->messageError("The selected times conflict with another booking. Please select another time or meeting room!");
            }
    

    please ignore the fields with the centre id and tennant id (unless you use these) they are there to ensure the booking is set to the right tennant and the right meeting room. use this as required and substitute what you need to.


    btw i am using p4a application framework so you will need to replace P4A::singleton()->messageError with the php error message mobober

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

Sidebar

Related Questions

I have an online reservation booking system (php script) that uses a mySQL database.
So I have a booking system where I have a 'lesson_type' table with 'lesson_type_id'
I have the following table SEASONS with time periods defining a booking prices for
I have a hotel booking system, when the user chooses the start date and
I'm working on an online booking system and currently use a table bookings (id,
For a booking system I have a table with rooms, arrival and departure. Example
i have a problem with my booking system. in the table rooms i have
Imagine that you want to design a tennis booking system. You have 5 tennis
I have had mysql query to check any particular reservations existing in database .
I have a mysql table which has data from all flight bookings on my

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.