How to Create a Hotel Room Reservation System with PHP, SQL and HTML

Learn how to create a simple hotel room booking system using PHP, SQL, and HTML. This article provides a step-by-step guide with code examples to help you get started. Whether you're building a hotel booking website or just need to add a booking feature to your existing website, this tutorial will teach you the basics of handling user inputs, storing data in a MySQL database, and displaying booking information to users.

Building a Hotel Room Booking System with PHP, SQL, and HTML
Hotel Room Booking System with PHP

Welcome to this tutorial on how to build a hotel room booking system using PHP, SQL, and HTML. In this article, we'll be showing you how to create a simple hotel booking system that allows users to book a room by filling out a form. This tutorial is perfect for beginners who are just starting with PHP and SQL. We'll walk you through every step of the process, from setting up your MySQL database to displaying the booking information to users. By the end of this tutorial, you'll have a fully functional hotel room booking system that you can customize to fit your needs. So, let's get started!

HTML code:

<!DOCTYPE html>
<html>
<head>
	<title>Hotel Room Booking</title>
</head>
<body>
	<h1>Book a Hotel Room</h1>
	<form action="book.php" method="post">
		<label for="name">Name:</label>
		<input type="text" name="name" id="name" required><br><br>
		<label for="email">Email:</label>
		<input type="email" name="email" id="email" required><br><br>
		<label for="checkin">Check-in Date:</label>
		<input type="date" name="checkin" id="checkin" required><br><br>
		<label for="checkout">Check-out Date:</label>
		<input type="date" name="checkout" id="checkout" required><br><br>
		<label for="roomtype">Room Type:</label>
		<select name="roomtype" id="roomtype">
			<option value="Standard">Standard</option>
			<option value="Deluxe">Deluxe</option>
			<option value="Suite">Suite</option>
		</select><br><br>
		<input type="submit" value="Book">
	</form>
</body>
</html>

PHP code:

<?php
$servername = "localhost";
$username = "yourusername";
$password = "yourpassword";
$dbname = "yourdatabasename";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Get user input
$name = $_POST["name"];
$email = $_POST["email"];
$checkin = $_POST["checkin"];
$checkout = $_POST["checkout"];
$roomtype = $_POST["roomtype"];

// Prepare SQL statement
$sql = "INSERT INTO bookings (name, email, checkin, checkout, roomtype)
VALUES ('$name', '$email', '$checkin', '$checkout', '$roomtype')";

// Execute SQL statement
if (mysqli_query($conn, $sql)) {
    echo "Booking successful!";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

SQL code:

CREATE TABLE bookings (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
email VARCHAR(50) NOT NULL,
checkin DATE NOT NULL,
checkout DATE NOT NULL,
roomtype VARCHAR(30) NOT NULL
);

Note: Replace "yourusername", "yourpassword", and "yourdatabasename" with your actual database credentials.

Conclusion:

This is a simple code for booking a hotel room using PHP, SQL, and HTML. The HTML form collects the necessary user inputs and sends them to the PHP code, which stores the data in a MySQL database using SQL queries. With some modifications and additional features, you can build a full-fledged hotel booking system using this code as a starting point.

Our website is for sale! The domain and website has been running for more than 3 years, but it's time to part with it. There is no price, so I consider any offer. Contact us if you are interested in buying in the feedback form, we will discuss options, price and details for transferring the site. (script, database and everything else for the site to work).