-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrent.php
184 lines (147 loc) · 5.22 KB
/
rent.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
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rent Form</title>
<link rel="stylesheet" href="style.css">
<style>
body {
background: url('img/SignBackGround.jpg') center center / cover;
background-size: cover;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}
h2 {
color: #333;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 300px;
margin: 0 auto;
}
label {
display: block;
margin-bottom: 8px;
color: #333;
}
input[type="date"],
input[type="text"],
input[type="number"],
select,
input[type="submit"] {
width: calc(100% - 12px);
padding: 8px;
margin-bottom: 15px;
border-radius: 3px;
border: 1px solid #4169E1;
}
input[type="submit"] {
background-color: #4169E1;
color: white;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: purple;
}
</style>
</head>
<body>
<h2>Rent Details</h2>
<form action="" method="post" enctype="multipart/form-data">
<h2>Add a Car Reservation</h2>
<label for="car_id">Select a Car:</label>
<select name="car_id" required>
<option value="">Select Car ID</option>
<?php
include 'config.php';
$sql = "SELECT car_id, car_model FROM car WHERE status = 'available'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['car_id'] . "'>" .
"ID: " . $row['car_id'] . " | Model: " . $row['car_model'] . "</option>";
}
} else {
echo "<option value=''>No cars available</option>";
}
$conn->close();
?>
</select>
<label for="ssn">Your SSN:</label>
<input type="text" id="ssn" name="ssn" required maxlength="20">
<label for="start_date">Start Date:</label>
<input type="date" id="start_date" name="start_date" required maxlength="20">
<label for="end_date">End Date:</label>
<input type="date" id="end_date" name="end_date" required maxlength="20">
<label for="no_of_days">Number of days:</label>
<input type="text" id="no_of_days" name="no_of_days" required maxlength="20">
<label for="location">Location:</label>
<input type="text" name="location" required maxlength="20">
<label for="email">Email:</label>
<input type="text" name="email" required maxlength="20">
<label for="office_id">Choose office :</label>
<select name="office_id" required>
<option value="">Select Office</option>
<?php
include 'config.php';
$sql = "SELECT office_id, office_name FROM office ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['office_id'] . "'>" .
"ID: " . $row['office_id'] . " | Office Name: " . $row['office_name'] . "</option>";
}
} else {
echo "<option value=''>No offices available</option>";
}
$conn->close();
?>
</select><br><br>
<input type="submit" name="submit" value="Add Reservation">
</form>
<form action="" method="post" enctype="multipart/form-data">
</form>
<?php
include 'config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
// Retrieve user inputs safely
$car_id = isset($_POST['car_id']) ? $_POST['car_id'] : '';
$start_date = isset($_POST['start_date']) ? $_POST['start_date'] : '';
$end_date = isset($_POST['end_date']) ? $_POST['end_date'] : '';
$location = isset($_POST['location']) ? $_POST['location'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$no_of_days = isset($_POST['no_of_days']) ? $_POST['no_of_days'] : '';
$office_id = isset($_POST['office_id']) ? $_POST['office_id'] : '';
$ssn = isset($_POST['ssn']) ? $_POST['ssn'] : '';
// Prepared statement for the reservation insertion
$stmt = $conn->prepare("INSERT INTO reservations (car_id, customer_id, start_date, end_date, location, email, no_of_days, office_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssis", $car_id, $ssn, $start_date, $end_date, $location, $email, $no_of_days, $office_id);
if ($stmt->execute()) {
// Update the car status to 'rented'
$update_stmt = $conn->prepare("UPDATE car SET status = 'rented' WHERE car_id = ?");
$update_stmt->bind_param("s", $car_id);
if ($update_stmt->execute()) {
echo "New record created successfully and car status updated to 'rented'";
} else {
echo "Error updating car status: " . $conn->error;
}
$update_stmt->close();
} else {
echo "Error inserting reservation: " . $stmt->error;
}
$stmt->close();
$conn->close();
// Redirect to the payment page
header("Location: payment.php");
exit();
}
?>
</body>
</html>