Project overview
The Hotel Booking Information System records reservations: the guest's name, the room number, and the check-in and check-out dates. Front desk staff can create bookings, see all of them in one list, adjust rooms or dates, and remove bookings after a confirmation step.
Problem it solves
Manual booking logs make it easy to write impossible stays, such as a check-out before check-in or a date like February 30, which leads to confusion at the front desk.
Key features
- Create, list, view, edit and delete bookings
- Date pickers for check-in and check-out
- Dates verified as real calendar dates in YYYY-MM-DD format
- Check-out must be later than check-in
- A confirmation page before a booking is removed
Case-specific rule
Real dates, and check-out after check-in
Both dates must be real calendar dates in YYYY-MM-DD format, and the check-out date must be later than the check-in date.
Database design
Database hotel_booking_db, table bookings, InnoDB with utf8mb4.
| Column | Type | Rule |
|---|---|---|
| id | INT AUTO_INCREMENT | Primary key, generated automatically. |
| guest_name | VARCHAR(100) | Required. Up to 100 characters. |
| room_number | VARCHAR(20) | Required. Up to 20 characters. |
| check_in | DATE | Required. A real date in YYYY-MM-DD format. |
| check_out | DATE | Required. A real date, later than the check-in date. |
From the code
The validation behind this case, exactly as written in create.php.
$validDate = function ($date) {
$parsed = DateTime::createFromFormat('!Y-m-d', $date);
return $parsed && $parsed->format('Y-m-d') === $date;
};
if (!$validDate($values['check_in']) || !$validDate($values['check_out'])) {
$errors[] = 'Enter valid dates in YYYY-MM-DD format.';
} elseif ($values['check_out'] <= $values['check_in']) {
$errors[] = 'Check-out date must be later than check-in date.';
}Challenges and solutions
01
Rejecting dates that do not exist
Challenge encountered
A date can look right and still be impossible, such as 2026-02-30.
Solution implemented
Each date is parsed with DateTime::createFromFormat and formatted back again. It is only accepted when both versions match exactly.
02
Stays that make sense
Challenge encountered
A booking whose check-out falls on or before its check-in should never be saved.
Solution implemented
Once both dates are valid, the YYYY-MM-DD values are compared directly, which keeps them in calendar order, and the save is refused with a specific message.
Outcome and impact
Bookings that always describe a real, valid stay, with date mistakes caught before they reach the database.
Every PHP file in the project passed syntax checking before submission.
- Files delivered
- 8
- PHP pages
- 6
- Table columns
- 5
- Sample records
- 3
Project files
Delivered in the required eight-file format, ready to drop into XAMPP.
config.phpOpens the PDO connection to the database, with exceptions turned on for errors.index.phpLists every record, newest first, with View, Edit and Delete links on each row.create.phpValidates a new record, saves it with a prepared INSERT, then redirects to the list.view.phpShows one record after checking that its ID is a positive whole number.edit.phpLoads an existing record, validates the changes and saves them with a prepared UPDATE.delete.phpShows a confirmation page, then deletes the record only on a confirmed POST.database.sqlCreates the database and table, then inserts three fictional sample records.README.mdSetup steps for XAMPP and phpMyAdmin, plus the feature list and local URL.
Secure by default
The same six practices protect all five examination cases.
- Prepared statementsEvery query runs through PDO prepared statements with named placeholders, so typed input never becomes part of the SQL.
- Escaped outputEvery value passes through htmlspecialchars with ENT_QUOTES and UTF-8 before it reaches the page, which blocks script injection.
- POST-only changesCreating, editing and deleting only happen on POST requests, and a delete needs an explicit confirmation first.
- Safe record IDsIDs must be positive whole numbers. A missing or invalid record returns a 404 with a clear Record not found page.
- Post, redirect, getAfter a successful save the page redirects to the list, so refreshing the browser never submits the form twice.
- Helpful validationFailed saves list every problem at once and keep what was typed, so nobody has to fill in the form again.
See it working
Add, edit and delete records in the live demo, and watch each prepared statement as it runs.