What is a simple way to check for room availability?
I have been working on a little project for class, just a simple, small hotel registration page that needs contact information and billing information. Bear in mind that unencrypted information is not an issue here.
Here is part of my process.php page:
$sql="INSERT INTO UMBRELLA (firstName, lastName, email, arrivalDate,
departureDate, adultGuests, childGuests, roomReservation, newsletterBool,
comments, creditCardType, creditCardNumber, expirationMonth, expirationYear,
securityCode, phone)
VALUES
('$_POST[firstName]','$_POST[lastName]','$_POST[email]', '$_POST[arrivalDate]',
'$_POST[departureDate]', '$_POST[adultGuests]', '$_POST[childGuests]',
'$_POST[roomReservation]', '$_POST[newsletterBool]', '$_POST[comments]',
'$_POST[creditCardType]', '$_POST[creditCardNumber]', '$_POST[expirationMonth]',
'$_POST[expirationYear]', '$_POST[securityCode]', '$_POST[phone]')";
I would prefer to keep the solution simple, as it’s only a minor requirement, so I don’t want to create additional tables for a many-to-many relationship (e.g. ROOMS table, BOOKINGS table). The roomReservation value only has three options: 1. Presidential Suite 2. Master Suite 3. Standard Suite. Basically, I would like to create a variable, $maxRooms, that is equal to 10.
$maxRooms=10;
I would then use a SELECT statement to get all useful data for each specific room type (note this is pseudocode so some formatting might be off):
$standard = "SELECT arrivalDate, departureDate, roomReservation FROM UMBRELLA
WHERE roomReservation = 'Standard Suite';"
$master = "SELECT arrivalDate, departureDate, roomReservation FROM UMBRELLA
WHERE roomReservation = 'Master Suite';"
$presidential = "SELECT arrivalDate, departureDate, roomReservation FROM
UMBRELLA WHERE roomReservation = 'Presidential Suite';"
I would then check how many rooms are reserved in a given date range, and if it was >=maxRooms then the page would output an error. This is the part I’m having trouble on. I would appreciate any help or insight! Thank you!
tl;dr What code do I need to compare the $standard, $master, and $presidential variables to a given date range?
So, they will be telling you which type of room they would like through something like a select input?
ie:
The max rooms: Does that refer to there being 10 master suites, 10 standard suites, and 10 presidential suites for a total of 30 rooms in all? If not, and it’s only 10 rooms in the whole ‘hotel’ how are the distributed across the three types? Also, I’m assuming you would not like the database to upload the new reservation if the rooms are full.
So, when someone clicks “Make Reservation” or whatever your submit button on the form is called, this checks to ensure the room type they have chosen is available. If it’s not they are they are all booked. If there are open rooms of the type they chose, they are reserved the room (which adds to the current number of rooms reserved of that type making it one less for the next) etc. You’d have to write something for checking out etc obviously.
Something like this? Honestly, I haven’t tried it etc…but is this the idea you are going for? I hope it helps a bit maybe…