Sure! Below is a comprehensive guide to building a Hotel Management System, including a MySQL database schema, file structure, layout design using Bootstrap 5, and complete PHP scripts for user authentication, room management, booking management, and report generation.

Project Introduction

The Hotel Management System is a comprehensive web application designed to streamline the operations of hotels, including room management, customer bookings, and payment processing. This platform allows hotel staff to manage room availability, handle customer reservations, and process payments efficiently. With features for reporting and room management, the system aims to enhance the overall guest experience while improving operational efficiency for hotel management.

Project Objectives

  • To develop a secure and user-friendly platform for managing hotel operations and customer interactions.
  • To implement a comprehensive database schema that supports hotel management, room bookings, and payment processing.
  • To provide functionalities for managing room availability and customer reservations effectively.
  • To facilitate payment processing for bookings and track payment statuses.
  • To create a responsive design that enhances user experience across various devices.
  • To generate reports for hotel management to analyze bookings and revenue.

Project Modules

  1. Hotel Management: Handles the addition, editing, and deletion of hotel information, including name, address, and contact details.
  2. Room Management: Manages room details, including room types, pricing, and availability status.
  3. Customer Management: Facilitates customer registration, authentication, and profile management.
  4. Booking Management: Allows customers to make, view, and cancel bookings for rooms.
  5. Payment Processing: Handles payment transactions for bookings, including payment amounts and dates.
  6. Availability Checking: Provides functionality to check room availability based on customer requirements.
  7. Reporting: Generates reports for hotel management to analyze booking trends and financial performance.

1. MySQL Database Schema


CREATE DATABASE hotel_management;
USE hotel_management;
-- Table for hotels
CREATE TABLE hotels (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
phone VARCHAR(20),
email VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Table for rooms
CREATE TABLE rooms (
id INT AUTO_INCREMENT PRIMARY KEY,
hotel_id INT NOT NULL,
room_number VARCHAR(10) NOT NULL,
room_type VARCHAR(50) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
status ENUM('available', 'booked') DEFAULT 'available',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (hotel_id) REFERENCES hotels(id) ON DELETE CASCADE
);
-- Table for customers
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
phone VARCHAR(20),
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Table for bookings
CREATE TABLE bookings (
id INT AUTO_INCREMENT PRIMARY KEY,
room_id INT NOT NULL,
customer_id INT NOT NULL,
check_in DATE NOT NULL,
check_out DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (room_id) REFERENCES rooms(id) ON DELETE CASCADE,
FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE
);
-- Table for payments
CREATE TABLE payments (
id INT AUTO_INCREMENT PRIMARY KEY,
booking_id INT NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
payment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (booking_id) REFERENCES bookings(id) ON DELETE CASCADE
);

2. File and Folder Structure


hotel_management_system/

├── config/
│ └── db.php

├── public/
│ ├── index.php
│ ├── login.php
│ ├── register.php
│ ├── dashboard.php
│ ├── rooms.php
│ ├── bookings.php
│ ├── reports.php
│ ├── add_room.php
│ ├── edit_room.php
│ ├── delete_room.php
│ ├── make_booking.php
│ ├── cancel_booking.php
│ └── check_availability.php

├── includes/
│ ├── header.php
│ ├── footer.php
│ └── functions.php

├── assets/
│ ├── css/
│ │ └── styles.css
│ ├── js/
│ │ └── scripts.js
│ └── images/

└── vendor/
└── (Bootstrap and other libraries)

3. Layout Based Design with Bootstrap 5

Header (includes/header.php)


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/styles.css">
<title>Hotel Management System</title>
</head>
<body>
<div class="container">
<header class="my-4">
<h1>Hotel Management System</h1>
</header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="dashboard.php">Dashboard</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="rooms.php">Rooms</a>
</li>
<li class="nav-item">
<a class="nav-link" href="bookings.php">Bookings</a>
</li>
<li class="nav-item">
<a class="nav-link" href="reports.php">Reports</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="my-4">

Footer (includes/footer.php)


</main>
<footer class="text-center my-4">
<p>© 2023 Hotel Management System. All rights reserved.</p>
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

4. PHP Code for User Authentication

Registration (public/register.php)


<?php
require '../config/db.php';
require '../includes/header.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$stmt = $conn->prepare("INSERT INTO customers (name, email, password) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $name, $email, $password);
$stmt->execute();
$stmt->close();
header("Location: login.php");
}
?>
<form method="POST" action="">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
<?php require '../includes/footer.php'; ?>

Login (public/login.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = $_POST['email'];
$password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM customers WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
header("Location: dashboard.php");
} else {
echo "Invalid credentials.";
}
}
?>
<form method="POST" action="">
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
<?php require '../includes/footer.php'; ?>

5. PHP Scripts for Managing Room Details

Add Room (public/add_room.php)


<?php
require '../config/db.php';
require '../includes/header.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$hotel_id = $_POST['hotel_id'];
$room_number = $_POST['room_number'];
$room_type = $_POST['room_type'];
$price = $_POST['price'];
$stmt = $conn->prepare("INSERT INTO rooms (hotel_id, room_number, room_type, price) VALUES (?, ?, ?, ?)");
$stmt->bind_param("issd", $hotel_id, $room_number, $room_type, $price);
$stmt->execute();
$stmt->close();
header("Location: rooms.php");
}
?>
<form method="POST" action="">
<div class="mb-3">
<label for="hotel_id" class="form-label">Hotel ID</label>
<input type="number" class="form-control" id="hotel_id" name="hotel_id" required >
</div>
<div class="mb-3">
<label for="room_number" class="form-label">Room Number</label>
<input type="text" class="form-control" id="room_number" name="room_number" required>
</div>
<div class="mb-3">
<label for="room_type" class="form-label">Room Type</label>
<input type="text" class="form-control" id="room_type" name="room_type" required>
</div>
<div class="mb-3">
<label for="price" class="form-label">Price</label>
<input type="number" step="0.01" class="form-control" id="price" name="price" required>
</div>
<button type="submit" class="btn btn-primary">Add Room</button>
</form>
<?php require '../includes/footer.php'; ?>

Edit Room (public/edit_room.php)


<?php
require '../config/db.php';
require '../includes/header.php';
if (isset($_GET['id'])) {
$room_id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM rooms WHERE id = ?");
$stmt->bind_param("i", $room_id);
$stmt->execute();
$result = $stmt->get_result();
$room = $result->fetch_assoc();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$room_number = $_POST['room_number'];
$room_type = $_POST['room_type'];
$price = $_POST['price'];
$stmt = $conn->prepare("UPDATE rooms SET room_number = ?, room_type = ?, price = ? WHERE id = ?");
$stmt->bind_param("ssdi", $room_number, $room_type, $price, $room_id);
$stmt->execute();
$stmt->close();
header("Location: rooms.php");
}
?>
<form method="POST" action="">
<div class="mb-3">
<label for="room_number" class="form-label">Room Number</label>
<input type="text" class="form-control" id="room_number" name="room_number" value="<?php echo $room['room_number']; ?>" required>
</div>
<div class="mb-3">
<label for="room_type" class="form-label">Room Type</label>
<input type="text" class="form-control" id="room_type" name="room_type" value="<?php echo $room['room_type']; ?>" required>
</div>
<div class="mb-3">
<label for="price" class="form-label">Price</label>
<input type="number" step="0.01" class="form-control" id="price" name="price" value="<?php echo $room['price']; ?>" required>
</div>
<button type="submit" class="btn btn-primary">Update Room</button>
</form>
<?php require '../includes/footer.php'; ?>

Delete Room (public/delete_room.php)


<?php
require '../config/db.php';
if (isset($_GET['id'])) {
$room_id = $_GET['id'];
$stmt = $conn->prepare("DELETE FROM rooms WHERE id = ?");
$stmt->bind_param("i", $room_id);
$stmt->execute();
$stmt->close();
header("Location: rooms.php");
}
?>

6. PHP Code for Booking Management
Check Availability (public/check_availability.php)

<?php
require '../config/db.php';
require '../includes/header.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$check_in = $_POST['check_in'];
$check_out = $_POST['check_out'];
$stmt = $conn->prepare("SELECT * FROM rooms WHERE id NOT IN (SELECT room_id FROM bookings WHERE (check_in <= ? AND check_out >= ?))");
$stmt->bind_param("ss", $check_out, $check_in);
$stmt->execute();
$result = $stmt->get_result();
$available_rooms = $result->fetch_all(MYSQLI_ASSOC);
}
?>
<form method="POST" action="">
<div class="mb-3">
<label for="check_in" class="form-label">Check In</label>
<input type="date" class="form-control" id="check_in" name="check_in" required>
</div>
<div class="mb-3">
<label for="check_out" class="form-label">Check Out</label>
<input type="date" class="form-control" id="check_out" name="check_out" required>
</div>
<button type="submit" class="btn btn-primary">Check Availability</button>
</form>
<?php if (isset($available_rooms)): ?>
<h3>Available Rooms</h3>
<table class="table">
<thead>
<tr>
<th>Room Number</th>
<th>Room Type</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($available_rooms as $room): ?>
<tr>
<td><?php echo $room['room_number']; ?></td>
<td><?php echo $room['room_type']; ?></td>
<td><?php echo $room['price']; ?></td>
<td>
<a href="make_booking.php?room_id=<?php echo $room['id']; ?>" class="btn btn-success">Book Now</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php require '../includes/footer.php'; ?>

Make Booking (public/make_booking.php)


<?php
require '../config/db.php';
require '../includes/header.php';
if (isset($_GET['room_id'])) {
$room_id = $_GET['room_id'];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$customer_id = $_SESSION['user_id'];
$room_id = $_POST['room_id'];
$check_in = $_POST['check_in'];
$check_out = $_POST['check_out'];
$stmt = $conn->prepare("INSERT INTO bookings (room_id, customer_id, check_in, check_out) VALUES (?, ?, ?, ?)");
$stmt->bind_param("iiss", $room_id, $customer_id, $check_in, $check_out);
$stmt->execute();
$stmt->close();
header("Location: bookings.php");
}
?>
<form method="POST" action="">
<input type="hidden" name="room_id" value="<?php echo $room_id; ?>">
<div class="mb-3">
<label for="check_in" class="form-label">Check In</label>
<input type="date" class="form-control" id="check_in" name="check_in" required>
</div>
<div class="mb-3">
<label for="check_out" class="form-label">Check Out</label>
<input type="date" class="form-control" id="check_out" name="check_out" required>
</div>
<button type="submit" class="btn btn-primary">Confirm Booking</button>
</form>
<?php require '../includes/footer.php'; ?>

Cancel Booking (public/cancel_booking.php)


<?php
require '../config/db.php';
if (isset($_GET['id'])) {
$booking_id = $_GET['id'];
$stmt = $conn->prepare("DELETE FROM bookings WHERE id = ?");
$stmt->bind_param("i", $booking_id);
$stmt->execute();
$stmt->close();
header("Location: bookings.php");
}
?>

6. PHP Code for Generating Reports for Bookings

Generate Report (public/reports.php)


<?php
require '../config/db.php';
require '../includes/header.php';
$stmt = $conn->prepare("SELECT b.id, r.room_number, c.name, b.check_in, b.check_out FROM bookings b JOIN rooms r ON b.room_id = r.id JOIN customers c ON b.customer_id = c.id");
$stmt->execute();
$result = $stmt->get_result();
$bookings = $result->fetch_all(MYSQLI_ASSOC);
?>
<h3>Booking Reports</h3>
<table class="table">
<thead>
<tr>
<th>Booking ID</th>
<th>Room Number</th>
<th>Customer Name</th>
<th>Check In</th>
<th>Check Out</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($bookings as $booking): ?>
<tr>
<td><?php echo $booking['id']; ?></td>
<td><?php echo $booking['room_number']; ?></td>
<td><?php echo $booking['name']; ?></td>
<td><?php echo $booking['check_in']; ?></td>
<td><?php echo $booking['check_out']; ?></td>
<td>
<a href="cancel_booking.php?id=<?php echo $booking['id']; ?>" class="btn btn-danger">Cancel</a </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php require '../includes/footer.php'; ?>

7. Logout Functionality

Logout (public/logout.php)


<?php
session_start();
session_destroy();
header("Location: login.php");
?>

8. Additional Features to Consider

User Roles and Permissions: Implement different user roles (admin, staff, customer) to manage access to various functionalities.

Email Notifications: Set up email notifications for booking confirmations, cancellations, and reminders.

Search Functionality: Add search filters for rooms and bookings to enhance user experience.

Payment Integration: Integrate payment gateways for online payments and manage payment statuses.

User Profile Management: Allow users to update their profiles and view booking history.

9. Security Measures

Input Validation: Ensure all user inputs are validated and sanitized to prevent SQL injection and XSS attacks.

Session Management: Implement secure session management practices to protect user sessions.

HTTPS: Use HTTPS to encrypt data transmitted between the client and server.

10. Testing and Deployment

Unit Testing: Write unit tests for your PHP scripts to ensure they function correctly.

User Acceptance Testing: Conduct testing with real users to gather feedback and make necessary adjustments.

Deployment: Choose a reliable hosting provider and deploy your application, ensuring all configurations are set correctly.

11. Documentation

User Manual: Create a user manual to guide users on how to navigate and use the system.

Developer Documentation: Document the codebase and architecture for future reference and maintenance.

12. Future Enhancements

Mobile Responsiveness: Ensure the user interface is mobile-friendly for better accessibility.

Analytics Dashboard: Implement analytics to track bookings, revenue, and user engagement.

Multi-language Support: Consider adding multi-language support to cater to a broader audience.

This comprehensive approach will help you build a robust Hotel Management System that meets user needs and adapts to future requirements.