Creating a Real Estate Booking System involves several components, including a MySQL database schema, file structure, layout design using Bootstrap 5, and complete PHP scripts for user authentication and management. Below is a comprehensive guide to help you set up your system.

Project Introduction

The Real Estate Booking System is designed to provide a comprehensive platform for buying, selling, and renting properties. This system allows users to create listings for properties, manage bookings, and facilitate payments. With a robust MySQL database backend, the platform ensures secure data management and a user-friendly experience for all roles, including administrators, buyers, sellers, and agents.

Project Objectives

  • To create a secure user registration and login system for buyers, sellers, agents, and administrators.
  • To enable sellers to create and manage property listings, including detailed descriptions and pricing.
  • To facilitate the booking process for buyers interested in properties.
  • To implement a payment system that supports various payment methods for booking properties.
  • To allow users to leave reviews and ratings for properties they have interacted with.
  • To provide notifications to users regarding booking statuses, new listings, and other important updates.
  • To manage documents related to properties, such as contracts and agreements.

Project Modules

  1. User Management: Handles user registration, login, and role-based access for admins, buyers, sellers, and agents.
  2. Property Management: Allows sellers to create, edit, and manage property listings, including details and pricing.
  3. Booking Management: Manages the booking process, including tracking booking statuses and buyer information.
  4. Payment Management: Facilitates payment processing for bookings, including tracking payment statuses.
  5. Review System: Collects and manages user reviews and ratings for properties.
  6. Notification System: Sends notifications to users about booking updates, new properties, and other important information.
  7. Document Management: Allows users to upload and manage documents related to properties, such as contracts and agreements.
  8. Admin Dashboard: Provides administrative tools for managing users, properties, bookings, and overall platform performance.

1. MySQL Database Schema


CREATE DATABASE real_estate_booking;
USE real_estate_booking;
-- Table for users
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
role ENUM('admin', 'buyer', 'seller', 'agent') DEFAULT 'buyer',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Table for properties
CREATE TABLE properties (
id INT AUTO_INCREMENT PRIMARY KEY,
owner_id `INT` NOT NULL,
title VARCHAR(255) NOT NULL,
description VARCHAR(255) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
location VARCHAR(255) NOT NULL,
property_type ENUM('residential', 'commercial', 'land') NOT NULL,
bedrooms INT,
bathrooms INT,
square_footage INT,
amenities VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Table for bookings
CREATE TABLE bookings (
id INT AUTO_INCREMENT PRIMARY KEY,
property_id `INT` NOT NULL,
buyer_id `INT` NOT NULL,
booking_date `DATETIME` NOT NULL,
status ENUM('pending', 'confirmed', 'canceled') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE,
FOREIGN KEY (buyer_id) REFERENCES users(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 `DATETIME` NOT NULL,
payment_method ENUM('credit_card', 'paypal', 'bank_transfer') NOT NULL,
status ENUM('completed', 'pending', 'failed') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (booking_id) REFERENCES bookings(id) ON DELETE CASCADE
);
-- Table for reviews
CREATE TABLE reviews (
id INT AUTO_INCREMENT PRIMARY KEY,
property_id `INT` NOT NULL,
user_id `INT` NOT NULL,
rating INT CHECK (rating >= 1 AND rating <= 5),
comment VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Table for notifications
CREATE TABLE notifications (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id `INT` NOT NULL,
message VARCHAR(255) NOT NULL,
is_read TINYINT(1) DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Table for documents
CREATE TABLE documents (
id INT AUTO_INCREMENT PRIMARY KEY,
property_id `INT` NOT NULL,
document_type ENUM('contract', 'agreement', 'disclosure') NOT NULL,
file_path VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE
);

2. File and Folder Structure


real_estate_booking_system/

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

├── public/
│ ├── index.php
│ ├── login.php
│ ├── register.php
│ ├── dashboard.php
│ ├── create_property.php
│ ├── edit_property.php
│ ├── view_property.php
│ ├── bookings.php
│ ├── payments.php
│ ├── reviews.php
│ ├── notifications.php
│ ├── documents.php
│ └── admin_dashboard.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>Real Estate Booking System</title>
</head>
<body>
<div class=`container`>
<header class=`my-4`>
<h1>Real Estate Booking System</h1>
</header>
<nav class=`navbar navbar-expand-lg navbar-light bg-light`>
<div class=`container-fluid`>
<a class=`navbar-brand` href=`index.php`>Home</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=`create_property.php`>Create Property</a>
</li>
<li class=`nav-item`>
<a class=`nav-link` href=`bookings.php`>My Bookings</a>
</li>
<li class=`nav-item`>
<a class=`nav-link` href=`payments.php`>Payments</a>
</li>
<li class=`nav-item`>
<a class=`nav-link` href=`reviews.php`>My Reviews</a>
</li>
<li class=`nav-item`>
<a class=`nav-link` href=`notifications.php`>Notifications</a>
</li>
<li class=`nav-item`>
<a class=`nav-link` href=`login.php`>Login</a>
</li>
<li class=`nav-item`>
<a class=`nav-link` href=`register.php`>Register</a>
</li>
</ul>
</div>
</div>
</nav>
<main class=`my-4`>

Footer (includes/footer.php)


</main>
<footer class=`text-center my-4`>
<p>© 2023 Real Estate Booking 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') {
$username = $_POST['username'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$role = $_POST['role'];
$stmt = $conn->prepare(`INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, ?)`);
$stmt->bind_param(`ssss`, $username, $email, $password, $role);
$stmt->execute();
$stmt->close();
header(`Location: login.php`);
}
?>
<form method=`POST` action=``>
<div class=`mb-3`>
<label for=`username` class=`form-label`>Username</label>
<input type=`text` class=`form-control` id=`username` name=`username` 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>
<div class=`mb-3`>
<label for=`role` class=`form-label`>Role</label>
<select class=`form-select` id=`role` name=`role`>
<option value=`buyer`>Buyer</option>
<option value=`seller`>Seller</option>
<option value=`agent`>Agent</option>
<option value=`admin`>Admin</option>
</select>
</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') {
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $conn->prepare(`SELECT * FROM users WHERE username = ?`);
$stmt->bind_param(`s`, $username);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['role'] = $user['role'];
header(`Location: dashboard.php`);
} else {
echo `Invalid credentials.`;
}
}
?>
<form method=`POST` action=``>
<div class=`mb-3`>
<label for=`username` class=`form-label`>Username</label>
<input type=`text` class=`form-control` id=`username` name=`username` 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. Additional PHP Scripts

Dashboard (public/dashboard.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if (!isset($_SESSION['user_id'])) {
header(`Location: login.php`);
exit();
}
$user_id = $_SESSION['user_id'];
$stmt = $conn->prepare(`SELECT * FROM users WHERE id = ?`);
$stmt->bind_param(`i`, $user_id);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
?>
<h2>Welcome, <?php echo $user['username']; ?></h2>
<p>Your role: <?php echo ucfirst($user['role']); ?></p>
<?php require '../includes/footer.php'; ?>

Property Management (public/property_management.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header(`Location: login.php`);
exit();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$title = $_POST['title'];
$description = $_POST['description'];
$price = $_POST['price'];
$location = $_POST['location'];
$property_type = $_POST['property_type'];
$stmt = $conn->prepare(`INSERT INTO properties (title, description, price, location, property_type) VALUES (?, ?, ?, ?, ?)`);
$stmt->bind_param(`ssiss`, $title, $description, $price, $location, $property_type);
$stmt->execute();
$stmt->close();
header(`Location: property_management.php`);
}
?>
<h2>Manage Properties</h2>
<form method=`POST` action=``>
<div class=`mb-3`>
<label for=`title` class=`form-label`>Property Title</label>
<input type=`text` class=`form-control` id=`title` name=`title` required>
</div>
<div class=`mb-3`>
<label for=`description` class=`form-label`>Description</label>
<textarea class=`form-control` id=`description` name=`description` required></textarea>
</div>
<div class=`mb-3`>
<label for=`price` class=`form-label`>Price</label>
<input type=`number` class=`form-control` id=`price` name=`price` required>
</div>
<div class=`mb-3`>
<label for=`location` class=`form-label`>Location</label>
<input type=`text` class=`form-control` id=`location` name=`location` required>
</div>
<div class=`mb-3`>
<label for=`property_type` class=`form-label`>Property Type</label>
<select class=`form-select` id=`property_type` name=`property_type` required>
<option value=`residential`>Residential</option>
<option value=`commercial`>Commercial</option>
<option value=`land`>Land</option>
</select>
</div>
<button type=`submit` class=`btn btn-primary`>Add Property</button>
</form>
<?php require '../includes/footer.php'; ?>

Booking Management (public/bookings.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if (!isset($_SESSION['user_id'])) {
header(`Location: login.php`);
exit();
}
$user_id = $_SESSION['user_id'];
$stmt = $conn->prepare(`SELECT bookings.*, properties.title AS property_title FROM bookings JOIN properties ON bookings.property_id = properties.id WHERE bookings.buyer_id = ?`);
$stmt->bind_param(`i`, $user_id);
$stmt->execute();
$result = $stmt->get_result();
$bookings = $result->fetch_all(MYSQLI_ASSOC);
?>
<h2>My Bookings</h2>
<table class=`table`>
<thead>
<tr>
<th>ID</th>
<th>Property</th>
<th>Booking Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($bookings as $booking): ?>
<tr>
<td><?php echo $booking['id']; ?></td>
<td><?php echo $booking['property_title']; ?></td>
<td><?php echo $booking['booking_date']; ?></td>
<td><?php echo ucfirst($booking['status']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php require '../includes/footer.php'; ?>

Payment Management (public/payments.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if (!isset($_SESSION['user_id'])) {
header(`Location: login.php`);
exit();
}
$user_id = $_SESSION['user_id'];
$stmt = $conn->prepare(`SELECT payments.*, bookings.id AS booking_id, properties.title AS property_title FROM payments JOIN bookings ON payments.booking_id = bookings.id JOIN properties ON bookings.property_id = properties.id WHERE bookings.buyer_id = ?`);
$stmt->bind_param(`i`, $user_id);
$stmt->execute();
$result = $stmt->get_result();
$payments = $result->fetch_all(MYSQLI_ASSOC);
?>
<h2>My Payments</h2>
<table class=`table`>
<thead>
<tr>
<th>ID</th>
<th>Booking ID</th>
<th>Property</th>
<th>Amount</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($payments as $payment): ?>
<tr>
<td><?php echo $payment['id']; ?></td>
<td><?php echo $payment['booking_id']; ?></td>
<td><?php echo $payment['property_title']; ?></td>
<td><?php echo $payment['amount']; ?></td>
<td><?php echo ucfirst($payment['status']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php require '../includes/footer.php'; ?>

Review Management (public/reviews.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if (!isset($_SESSION['user_id'])) {
header(`Location: login.php`);
exit();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$property_id = $_POST['property_id'];
$user_id = $_SESSION['user_id'];
$rating = $_POST['rating'];
$comment = $_POST['comment'];
$stmt = $conn->prepare(`INSERT INTO reviews (property_id, user_id, rating, comment) VALUES (?, ?, ?, ?)`);
$stmt->bind_param(`iiis`, $property_id, $user_id, $rating, $comment);
$stmt->execute();
$stmt->close();
header(`Location: reviews.php`);
}
$stmt = $conn->prepare(`SELECT * FROM properties`);
$stmt->execute();
$result = $stmt->get_result();
$properties = $result->fetch_all(MYSQLI_ASSOC);
?>
<h2>Leave a Review</h2>
<form method=`POST` action=``>
<div class=`mb-3`>
<label for=`property_id` class=`form-label`>Property</label>
<select class=`form-select` id=`property_id` name=`property_id` required>
<?php foreach ($properties as $property): ?>
<option value=`<?php echo $property['id']; ?>`><?php echo $property['title']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class=`mb-3`>
<label for=`rating` class=`form-label`>Rating </label>
<select class=`form-select` id=`rating` name=`rating` required>
<option value=`1`>1</option>
<option value=`2`>2</option>
<option value=`3`>3</option>
<option value=`4`>4</option>
<option value=`5`>5</option>
</select>
</div>
<div class=`mb-3`>
<label for=`comment` class=`form-label`>Comment</label>
<textarea class=`form-control` id=`comment` name=`comment` required></textarea>
</div>
<button type=`submit` class=`btn btn-primary`>Submit Review</button>
</form>
<h3>Existing Reviews</h3>
<table class=`table`>
<thead>
<tr>
<th>Property</th>
<th>User</th>
<th>Rating</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $conn->prepare(`SELECT reviews.*, properties.title AS property_title, users.username AS user_name FROM reviews JOIN properties ON reviews.property_id = properties.id JOIN users ON reviews.user_id = users.id`);
$stmt->execute();
$result = $stmt->get_result();
$reviews = $result->fetch_all(MYSQLI_ASSOC);
foreach ($reviews as $review): ?>
<tr>
<td><?php echo $review['property_title']; ?></td>
<td><?php echo $review['user_name']; ?></td>
<td><?php echo $review['rating']; ?></td>
<td><?php echo $review['comment']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php require '../includes/footer.php'; ?>

Notification Management (public/notifications.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if (!isset($_SESSION['user_id'])) {
header(`Location: login.php`);
exit();
}
$user_id = $_SESSION['user_id'];
$stmt = $conn->prepare(`SELECT * FROM notifications WHERE user_id = ? ORDER BY created_at DESC`);
$stmt->bind_param(`i`, $user_id);
$stmt->execute();
$result = $stmt->get_result();
$notifications = $result->fetch_all(MYSQLI_ASSOC);
?>
<h2>My Notifications</h2>
<ul class=`list-group`>
<?php foreach ($notifications as $notification): ?>
<li class=`list-group-item`>
<?php echo $notification['message']; ?>
<small class=`text-muted`><?php echo $notification['created_at']; ?></small>
</li>
<?php endforeach; ?>
</ul>
<?php require '../includes/footer.php'; ?>

Document Management (public/documents.php)


<?php
session_start();
require '../config/db.php';
require '../includes/header.php';
if (!isset($_SESSION['user_id'])) {
header(`Location: login.php`);
exit();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$property_id = $_POST['property_id'];
$document_type = $_POST['document_type'];
$file_path = $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], `uploads/` . $file_path);
$stmt = $conn->prepare(`INSERT INTO documents (property_id, document_type, file_path) VALUES (?, ?, ?)`);
$stmt->bind_param(`iss`, $property_id, $document_type, $file_path);
$stmt->execute();
$stmt->close();
header(`Location: documents.php`);
}
$stmt = $conn->prepare(`SELECT * FROM properties`);
$stmt->execute();
$result = $stmt->get_result();
$properties = $result->fetch_all(MYSQLI_ASSOC);
?>
<h2>Upload Documents</h2>
<form method=`POST` action=`` enctype=`multipart/form-data`>
<div class=`mb-3`>
<label for=`property_id` class=`form-label`>Property</label>
<select class=`form-select` id=`property_id` name=`property_id` required>
<?php foreach ($properties as $property): ?>
<option value=`<?php echo $property['id']; ?>`><?php echo $property['title']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class=`mb-3`>
<label for=`document_type` class=`form-label`>Document Type</label>
<select class=`form-select` id=`document_type` name=`document_type` required>
<option value=`contract`>Contract</option>
<option value=`agreement`>Agreement</option>
<option value =`disclosure`>Disclosure</option>
</select>
</div>
<div class=`mb-3`>
<label for=`file` class=`form-label`>Upload File</label>
<input type=`file` class=`form-control` id=`file` name=`file` required>
</div>
<button type=`submit` class=`btn btn-primary`>Upload Document</button>
</form>
<h3>Uploaded Documents</h3>
<table class=`table`>
<thead>
<tr>
<th>Property</th>
<th>Document Type</th>
<th>File Path</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $conn->prepare(`SELECT documents.*, properties.title AS property_title FROM documents JOIN properties ON documents.property_id = properties.id`);
$stmt->execute();
$result = $stmt->get_result();
$documents = $result->fetch_all(MYSQLI_ASSOC);
foreach ($documents as $document): ?>
<tr>
<td><?php echo $document['property_title']; ?></td>
<td><?php echo ucfirst($document['document_type']); ?></td>
<td><a href=`uploads/<?php echo $document['file_path']; ?>` target=`_blank`>View Document</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php require '../includes/footer.php'; ?>

6. Additional Features to Consider

Advanced Search and Filtering: Implement more sophisticated search algorithms to enhance user experience.

User Dashboard: Create personalized dashboards for users to manage their properties, bookings, and payments.

Mobile Responsiveness: Ensure the application is fully responsive for mobile users.

7. Security Measures

Input Validation: Validate all user inputs to prevent SQL injection and XSS attacks.

File Upload Security: Implement checks for file types and sizes to secure document uploads.

Session Management: Use secure session handling practices to protect user sessions.

8. Testing and Deployment

Unit Testing: Conduct thorough unit tests for all components to ensure functionality.

Integration Testing: Test the integration of various modules to ensure they work together seamlessly.

Deployment: Choose a reliable hosting provider and deploy the application, ensuring all configurations are optimized for performance.

9. Documentation

User Documentation: Create a user manual to guide users through the platform's features and functionalities.

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

10. Future Enhancements

AI Integration: Implement AI features for property recommendations based on user preferences.

Enhanced Communication Tools: Develop chat features for real-time communication between users and agents.

Marketing Tools: Create tools for agents to promote their listings effectively.

This structured approach will help you build a comprehensive Real Estate Booking System that meets user needs and adapts to future requirements.