-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminhotel.php
257 lines (216 loc) · 7.99 KB
/
adminhotel.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
session_start();
include ("database/connection.php");
include ("_admin.php");
$conn = new mysqli('localhost', 'root', '', 'travel');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Handle form submission for insertion
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['insert'])) {
$name = $_POST['name'];
$location = $_POST['location'];
$availability_status = $_POST['availability_status'];
$description = $_POST['description'];
$rating = $_POST['rating'];
$image_path = $_POST['image_path'];
$price = $_POST['price'];
$sql_insert = "INSERT INTO hotel (name, location, availability_status, description, rating, image_path, price)
VALUES ('$name', '$location', '$availability_status', '$description', '$rating', '$image_path', '$price')";
if ($conn->query($sql_insert) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql_insert . "<br>" . $conn->error;
}
}
// Handle form submission for updating availability status
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update'])) {
$hotel_id = $_POST['hotel_id'];
$availability_status = $_POST['availability_status'];
$sql_update = "UPDATE hotel SET availability_status='$availability_status' WHERE hotel_id=$hotel_id";
if ($conn->query($sql_update) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
}
$sql = "SELECT hotel_id, name, location, availability_status, description, rating, image_path, price FROM hotel";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>hotel Listings</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
display: flex;
width: 100%;
}
.forms {
width: 30%;
padding: 20px;
background-color: #f7f7f7;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
}
.table-container {
width: 70%;
padding: 20px;
}
h2, h3 {
margin-top: 0;
}
form {
margin-bottom: 20px;
}
label {
display: block;
margin-top: 10px;
font-weight: bold;
}
input[type="text"],
input[type="number"],
textarea,
select {
width: calc(100% - 20px);
padding: 10px;
margin-top: 5px;
border: 1px solid #ddd;
border-radius: 5px;
}
input[type="submit"] {
margin-top: 10px;
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
}
th {
background-color: #4CAF50;
color: white;
text-align: left;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
button {
padding: 5px 10px;
color: white;
background-color: red;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: darkred;
}
</style>
<script>
function deleteRow(row) {
var table = document.getElementById("hotelTable");
table.deleteRow(row.parentNode.parentNode.rowIndex);
}
</script>
</head>
<body>
<div class="container">
<div class="forms">
<h3>Insert New hotel</h3>
<form method="POST" action="">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="location">Location:</label>
<input type="text" id="location" name="location" required>
<label for="availability_status">Availability Status:</label>
<select id="availability_status" name="availability_status" required>
<option value="Available">Available</option>
<option value="Not Available">Not Available</option>
</select>
<label for="description">Description:</label>
<textarea id="description" name="description" required></textarea>
<label for="rating">Rating:</label>
<input type="number" id="rating" name="rating" required>
<label for="image_path">Image Path:</label>
<input type="text" id="image_path" name="image_path" required>
<label for="price">Price:</label>
<input type="number" id="price" name="price" required>
<input type="submit" name="insert" value="Insert">
</form>
<h3>Update hotel Availability Status</h3>
<form method="POST" action="">
<label for="hotel_id">hotel ID:</label>
<input type="number" id="hotel_id" name="hotel_id" required>
<label for="availability_status">Availability Status:</label>
<select id="availability_status" name="availability_status" required>
<option value="available">Available</option>
<option value="Not Available">Not Available</option>
</select>
<input type="submit" name="update" value="Update">
</form>
</div>
<div class="table-container">
<h2>hotel Listings</h2>
<table id="hotelTable">
<tr>
<th>hotel ID</th>
<th>Name</th>
<th>Location</th>
<th>Availability Status</th>
<th>Description</th>
<th>Rating</th>
<th>Image</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$description = $row["description"];
$description_words = explode(' ', $description);
if (count($description_words) > 10) {
$description = implode(' ', array_slice($description_words, 0, 10)) . '...';
}
echo "<tr>";
echo "<td>" . $row["hotel_id"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["location"] . "</td>";
echo "<td>" . $row["availability_status"] . "</td>";
echo "<td>" . $description . "</td>";
echo "<td>" . $row["rating"] . "</td>";
echo "<td><img src='" . $row["image_path"] . "' alt='Image' width='50'></td>";
echo "<td>" . $row["price"] . "</td>";
echo "<td><button onclick='deleteRow(this)'>Delete</button></td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='9'>No records found</td></tr>";
}
$conn->close();
?>
</table>
</div>
</div>
</body>
</html>