EDIT: The query Gordon posted appears to have a problem. If I have a booking from 10-12 it seems to consider all bookings past 12 pm invalid, but all bookings before 10am valid.
Some quick and simple thinking ended up in me creating the following query:
SELECT serverip
FROM server
WHERE serverip NOT IN (SELECT serverip
FROM booking
WHERE startat >= datehere
AND expiresat <= datehere)
LIMIT 1;
Suppose the booking table stores the following:
+-----------+-----------+----------+----------+-----------+
| bookingid | serverip | username | startat | expiresat |
+-----------+-----------+----------+----------+-----------+
| 1 | 127.0.0.1 | testuser | 10:00 | 12:00 |
+-----------+-----------+----------+----------+-----------+
If the user was to input the following data for a booking:
startat = 9:59
expiresat = 12:01
They could easily bypass my check to see if the booking time is available based on previous bookings stored.
Any advice on how I could better solve this problem?
I would prefer NOT to limit the users input and would like to avoid hard coding specific time slots, if that wasn’t a problem however I would stick with what I’ve got.
Thanks for your time.
Where 8:00 is start time and 9:00 is expire.