Skip to content

Commit dd37dd7

Browse files
committed
this is for third round
1 parent f7621d3 commit dd37dd7

25 files changed

Lines changed: 1990 additions & 0 deletions

B240084EC_3/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Hotel Booking System
2+
3+
A complete hotel booking system with separated frontend and backend architecture.
4+
5+
## Project Structure
6+
7+
```
8+
├── assests/── images/ # Image assets
9+
10+
11+
├── frontend/ # Frontend HTML pages and images
12+
│ ├── index.html # Main homepage
13+
│ ├── login.html # Login page
14+
│ ├── signup.html # Registration page
15+
│ ├── checkin.html # Booking form page
16+
│ ├── details.html # Static booking details page
17+
18+
19+
├── backend/ # Backend files (PHP)
20+
│ ├── login.php # Login processing
21+
│ ├── signup.php # Registration processing
22+
│ ├── booking.php # Booking processing
23+
│ ├── details.php # Dynamic booking details page
24+
│ ├── logout.php # Logout processing
25+
26+
27+
├── mysql/── config
28+
│ └── database.php # Database connection
29+
└── index.php # Root redirect to frontend
30+
```
31+
32+
## Features
33+
34+
- User registration and login
35+
- Hotel booking system
36+
- Booking management
37+
- Responsive design
38+
- Session management
39+
- Database integration
40+
41+
## Setup
42+
43+
1. Place the project in your web server directory (e.g., `htdocs`)
44+
2. Create a MySQL database named `hotelbook`
45+
3. Import the database schema
46+
5. Access the application through your web server
47+
48+
## Usage
49+
50+
- Visit the root URL to access the homepage
51+
- All frontend files are in the `frontend/` directory
52+
- All backend processing files are in the `backend/` directory
53+
- The system automatically redirects between frontend and backend as needed
295 KB
Loading
442 KB
Loading
677 KB
Loading
322 KB
Loading
373 KB
Loading

B240084EC_3/backend/booking.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
session_start();
3+
require_once __DIR__ . '/../mysql/config/database.php';
4+
5+
if (!isset($_SESSION['user_id'])) {
6+
echo "<script>alert('Please login to book.'); window.location.href='../frontend/login.html';</script>";
7+
exit();
8+
}
9+
10+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
11+
$checkin = isset($_POST['checkin_date']) ? $_POST['checkin_date'] : '';
12+
$checkout = isset($_POST['checkout_date']) ? $_POST['checkout_date'] : '';
13+
$guests = isset($_POST['guests']) ? (int)$_POST['guests'] : 0;
14+
$roomType = isset($_POST['room_type']) ? $_POST['room_type'] : '';
15+
16+
if ($checkin === '' || $checkout === '' || $guests <= 0 || $roomType === '') {
17+
echo "<script>alert('All booking fields are required.'); window.location.href='../frontend/checkin.html';</script>";
18+
exit();
19+
}
20+
21+
if (strtotime($checkout) <= strtotime($checkin)) {
22+
echo "<script>alert('Check-out must be after check-in.'); window.location.href='../frontend/checkin.html';</script>";
23+
exit();
24+
}
25+
26+
$userId = $_SESSION['user_id'];
27+
28+
$stmt = mysqli_prepare($conn, "INSERT INTO bookings (user_id, checkin_date, checkout_date, guests, room_type, status) VALUES (?, ?, ?, ?, ?, 'confirmed')");
29+
mysqli_stmt_bind_param($stmt, 'issis', $userId, $checkin, $checkout, $guests, $roomType);
30+
if (mysqli_stmt_execute($stmt)) {
31+
echo "<script>alert('Booking confirmed!'); window.location.href='details.php';</script>";
32+
exit();
33+
}
34+
35+
echo "<script>alert('Failed to create booking.'); window.location.href='../frontend/checkin.html';</script>";
36+
}
37+
?>

B240084EC_3/backend/details.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
session_start();
3+
require_once __DIR__ . '/../mysql/config/database.php';
4+
5+
if (!isset($_SESSION['user_id'])) {
6+
echo "<script>alert('Please login to view your bookings.'); window.location.href='../frontend/login.html';</script>";
7+
exit();
8+
}
9+
10+
$userId = $_SESSION['user_id'];
11+
12+
$query = "SELECT id, checkin_date, checkout_date, guests, room_type, status FROM bookings WHERE user_id = ? ORDER BY created_at DESC";
13+
$stmt = mysqli_prepare($conn, $query);
14+
mysqli_stmt_bind_param($stmt, 'i', $userId);
15+
mysqli_stmt_execute($stmt);
16+
$result = mysqli_stmt_get_result($stmt);
17+
$bookings = $result ? mysqli_fetch_all($result, MYSQLI_ASSOC) : [];
18+
?>
19+
<!DOCTYPE html>
20+
<html lang="en">
21+
<head>
22+
<meta charset="UTF-8">
23+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
24+
<title>My Bookings | HotelBook</title>
25+
<link rel="stylesheet" href="../frontend/detailsstyle.css">
26+
<link rel="stylesheet" href="../frontend/style.css">
27+
</head>
28+
<body>
29+
30+
<nav class="navbar">
31+
<div class="logo">HotelBook</div>
32+
<ul class="nav-links">
33+
<li><a href="../frontend/index.html">Home</a></li>
34+
<li><a href="details.php" target="_blank">Bookings</a></li>
35+
<li><a href="../frontend/checkin.html" class="btn " target="_blank">Book Now</a></li>
36+
<li><a href="logout.php">Logout</a></li>
37+
</ul>
38+
</nav>
39+
40+
<div class="bookings-container">
41+
<h2>My Reservations</h2>
42+
<p>Here are your current and past bookings.</p>
43+
44+
<table class="bookings-table">
45+
<thead>
46+
<tr>
47+
<th>Booking ID</th>
48+
<th>Check-in</th>
49+
<th>Check-out</th>
50+
<th>Guests</th>
51+
<th>Room Type</th>
52+
<th>Status</th>
53+
</tr>
54+
</thead>
55+
<tbody>
56+
<?php if (empty($bookings)) { ?>
57+
<tr>
58+
<td colspan="6">No bookings found.</td>
59+
</tr>
60+
<?php } else { ?>
61+
<?php foreach ($bookings as $b) { ?>
62+
<tr>
63+
<td>#HB<?php echo htmlspecialchars($b['id']); ?></td>
64+
<td><?php echo htmlspecialchars($b['checkin_date']); ?></td>
65+
<td><?php echo htmlspecialchars($b['checkout_date']); ?></td>
66+
<td><?php echo htmlspecialchars($b['guests']); ?></td>
67+
<td><?php echo htmlspecialchars(ucfirst($b['room_type'])); ?></td>
68+
<td><span class="status <?php echo htmlspecialchars($b['status']); ?>"><?php echo htmlspecialchars(ucfirst($b['status'])); ?></span></td>
69+
</tr>
70+
<?php } ?>
71+
<?php } ?>
72+
</tbody>
73+
</table>
74+
</div>
75+
76+
</body>
77+
</html>

B240084EC_3/backend/index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
// Redirect to frontend index.html
3+
header('Location: frontend/index.html');
4+
exit();
5+
?>

B240084EC_3/backend/login.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
session_start();
3+
require_once __DIR__ . '/../mysql/config/database.php';
4+
5+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
6+
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
7+
$pass = isset($_POST['password']) ? $_POST['password'] : '';
8+
9+
if ($email === '' || $pass === '') {
10+
echo "<script>alert('Provide both email and password'); window.location.href='../frontend/login.html';</script>";
11+
exit;
12+
}
13+
14+
$stmt = mysqli_prepare($conn, "SELECT id, name, email, password FROM users WHERE email = ?");
15+
mysqli_stmt_bind_param($stmt, 's', $email);
16+
mysqli_stmt_execute($stmt);
17+
$result = mysqli_stmt_get_result($stmt);
18+
$user = $result ? mysqli_fetch_assoc($result) : null;
19+
20+
if ($user && password_verify($pass, $user['password'])) {
21+
$_SESSION['user_id'] = $user['id'];
22+
$_SESSION['user_name'] = $user['name'];
23+
$_SESSION['user_email'] = $user['email'];
24+
header('Location: ../frontend/index.html');
25+
exit;
26+
}
27+
28+
echo "<script>alert('Invalid email or password'); window.location.href='../frontend/login.html';</script>";
29+
}
30+
?>

0 commit comments

Comments
 (0)