-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomerbooking.php
111 lines (90 loc) · 3.31 KB
/
customerbooking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
session_start();
// Check if the business name is set in the session
if (isset($_SESSION["name"])) {
$businessName = $_SESSION["name"];
} else {
$businessName = "Business Name Not Set";
}
// Define your database connection variables
$servername = "localhost";
$username = "Atharav"; // Replace with your database username
$password = "Atharav@31"; // Replace with your database password
$dbname = "project"; // Replace with your database name
// Create a database connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check if the connection was successful
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST["status"])) {
// Get the selected status value
$selectedStatus = $_POST["status"];
// Update the status in the "hotel" table for the specific business name
$updateSql = "UPDATE hotel SET status = ? WHERE name = ?";
// Prepare the statement
$updateStmt = $conn->prepare($updateSql);
if ($updateStmt === false) {
die("Prepare failed: " . $conn->error);
}
// Bind parameters and execute the update statement
$updateStmt->bind_param("ss", $selectedStatus, $businessName);
$updateStmt->execute();
// Close the update statement
$updateStmt->close();
$message = 'Status has been updated to ' . $selectedStatus;
// Call the JavaScript function to show the alert
echo '<script>showStatusUpdateAlert("' . $message . '");</script>';
}
// SQL query to fetch data from the "orders" and "details" tables for a specific hotel with GROUP BY
$sql = "SELECT d.custname, o.`dish_name` AS menu_item, d.`price` AS total_price, d.person, d.date, d.time,d.status,d.id
FROM orders o
JOIN details d ON o.d_id = d.id
JOIN menus m ON o.`dish_name` = m.`dish_name`
WHERE d.hotelname = '$businessName'
GROUP BY o.d_id, d.custname";
// Prepare the statement
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
// Execute the query
$stmt->execute();
$result = $stmt->get_result();
// Check if there are rows returned
if ($result->num_rows > 0) {
echo "Business Name: " . $businessName; // Display the business name
// Output data of each row
echo "<table border='1'>
<thead>
<tr>
<th>id</th>
<th>Customer Name</th>
<th>Date</th>
<th>Time</th>
<th>Number of Persons</th>
<th>Total Price</th>
<th>status</th>
</tr>
</thead>
<tbody>";
// Output data of each row
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td><a href='menuhotelhtml.php?custname=" . $row["custname"] . "&id=" . $row["id"] . "'>" . $row["custname"] . "</a></td>";
echo "<td>" . $row["date"] . "</td>"; // Display date
echo "<td>" . $row["time"] . "</td>"; // Display time
echo "<td>" . $row["person"] . "</td>";
echo "<td>" . $row["total_price"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo "</tr>";
}
echo "</tbody></table>";
} else {
echo "No data found for Hotel $businessName.";
}
// Close the statement and the database connection
$stmt->close();
$conn->close();
?>