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
This is my query, just edit the values as you need it
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->
to go one further:
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):
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:
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()->messageErrorwith the php error message mobober