-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-flight.php
295 lines (258 loc) · 11.6 KB
/
add-flight.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
session_start();
if (!isset($_SESSION['user_type'])) {
header('location: login.php');
}
require_once('includes/showMessage.php');
require 'includes/functions.php';
displaySessionMessage();
require 'connection.php';
if (isset($_POST['flight_but'])) {
// Retrieve form data
$source_date = $_POST['source_date'];
$source_time = $_POST['source_time'];
$dest_date = $_POST['dest_date'];
$dest_time = $_POST['dest_time'];
$dep_airport = $_POST['dep_airport'];
$arr_airport = $_POST['arr_airport'];
$seats = $_POST['seats'];
$price = $_POST['price'];
$flight_class = $_POST['flight_class']; // Added flight_class
$airline_name = $_POST['airline_name']; // You may need to retrieve this value too
// Perform database insert
$sql = "INSERT INTO flight (source_date, source_time, dest_date, dest_time, dep_airport, arr_airport, seats, price, flight_class, airline_name, dep_airport_id, arr_airport_id, airline_email)
VALUES ('$source_date', '$source_time', '$dest_date', '$dest_time', '$dep_airport', '$arr_airport', $seats, $price, '$flight_class', '$airline_name', $dep_airport_id, $arr_airport_id, '$airline_email')";
if (mysqli_query($con, $sql)) {
// Flight record inserted successfully
// You can add a success message or redirect to another page
} else {
// Error handling for the database insert
echo 'Error: ' . mysqli_error($con);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php require 'connection.php'; ?>
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" />
<link rel="stylesheet" href="form.css">
<title>Add Flight</title>
</head>
<body>
<style>
body {
background-color: #f5f5f5;
font-family: Arial, sans-serif;
}
.container {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 30px;
margin-top: 20px;
}
h3 {
font-size: 28px;
color: #333;
margin-bottom: 20px;
}
label {
font-size: 18px;
color: #333;
}
input[type="date"],
input[type="time"],
input[type="number"],
select {
border: none;
border-bottom: 2px solid #5c5c5c;
border-radius: 0;
font-weight: bold;
background-color: #f5f5f5;
width: 100%;
padding: 10px;
margin: 10px 0;
font-size: 16px;
color: #333;
}
.form-row {
margin-bottom: 20px;
}
.btn-success {
background-color: #4CAF50;
border: none;
padding: 10px 30px;
font-size: 18px;
border-radius: 5px;
cursor: pointer;
color: #fff;
transition: background-color 0.3s;
}
.btn-success:hover {
background-color: #45a049;
}
</style>
<?php include('includes/admin-nav.php'); ?>
<div class="container mt-0">
<div class="row">
<?php
if (isset($_GET['error'])) {
if ($_GET['error'] === 'destless') {
echo "<script>alert('Dest. date/time is less than src.');</script>";
} else if ($_GET['error'] === 'sqlerr') {
echo "<script>alert('Database error');</script>";
} else if ($_GET['error'] === 'same') {
echo "<script>alert('Same city specified in source and destination');</script>";
}
}
?>
<div class="bg-light form-out col-md-12">
<h3 class="text-secondary text-center">ADD FLIGHT DETAILS</h3>
<form method="POST" class="text-center" action="flightinc.php">
<div class="form-row mb-4">
<div class="col-md-3 p-0">
<h5 class="mb-0 form-name">DEPARTURE</h5>
</div>
<div class="col">
<input type="date" name="source_date" class="form-control" required>
</div>
<div class="col">
<input type="time" name="source_time" class="form-control" required>
</div>
</div>
<div class="form-row mb-4">
<div class="col-md-3 ">
<h5 class="form-name mb-0">ARRIVAL</h5>
</div>
<div class="col">
<input type="date" name="dest_date" class="form-control" required>
</div>
<div class="col">
<input type="time" name="dest_time" class="form-control" required>
</div>
</div>
<div class="form-row mb-4">
<div class="col">
<?php
// Construct the SQL query to select all airport names
$sql = 'SELECT airport_name FROM airport';
// Execute the SQL query
$result = mysqli_query($con, $sql);
// Check if the query was successful
if ($result) {
echo '<select class="mt-4" name="dep_airport" style="border: 0px; border-bottom:
2px solid #5c5c5c; background-color: whitesmoke !important;
font-weight: bold !important;
width:80%" required>
<option value="" disabled selected>From</option>';
// Loop through the results and create an option for each airport
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="' . $row['airport_name'] . '">' . $row['airport_name'] . '</option>';
}
echo '</select>';
} else {
// Handle the case where the query fails
echo 'Error: Unable to fetch airport data.';
}
?>
</div>
<div class="col">
<?php
// Construct the SQL query to select all airport names
$sql = 'SELECT airport_name FROM airport';
// Execute the SQL query
$result = mysqli_query($con, $sql);
// Check if the query was successful
if ($result) {
echo '<select class="mt-4" name="arr_airport" style="border: 0px; border-bottom:
2px solid #5c5c5c; background-color: whitesmoke !important;
font-weight: bold !important;
width:80%" required>
<option value="" disabled selected> To </option>';
// Loop through the results and create an option for each airport
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="' . $row['airport_name'] . '">' . $row['airport_name'] . '</option>';
}
echo '</select>';
} else {
// Handle the case where the query fails
echo 'Error: Unable to fetch airport data.';
}
?>
</div>
</div>
<div class="form-row">
<div class="col">
<div class="input-group">
<label for="dura">Seats:</label>
<input type="number" name="seats" id="dura" required />
</div>
</div>
<div class="col">
<div class="input-group">
<label for="price">Price:</label>
<input type="number" style="border: 0px; border-bottom: 2px solid #5c5c5c;" name="price" id="price"
required />
</div>
</div>
<div class="col">
<select class="form-control" name="flight_class" required>
<option value="" disabled selected>Select Flight Class</option>
<option value="Economy">Economy</option>
<option value="Business">Business</option>
<option value="First Class">First Class</option>
</select>
</div>
<div class="col">
<?php
// Construct the SQL query to select all airline names
$sql = 'SELECT airline_name FROM airline';
// Execute the SQL query
$result = mysqli_query($con, $sql);
// Check if the query was successful
if ($result) {
echo '<select class="airline col-md-3 mt-4" name="airline_name" style="border: 0px; border-bottom:
2px solid #5c5c5c; background-color: whitesmoke !important;" required>
<option value="" disabled selected>Select Airline</option>';
// Loop through the results and create an option for each airline
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="' . $row['airline_name'] . '">' . $row['airline_name'] . '</option>';
}
echo '</select>';
} else {
// Handle the case where the query fails
echo 'Error: Unable to fetch airline data.';
}
?>
</div>
</div>
<button name="flight_but" type="submit" class="btn btn-success mt-5">
<div style="font-size: 1.5rem;">
<i class="fa fa-lg fa-arrow-right"></i>Submit
</div>
</button>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$('.input-group input').focus(function () {
me = $(this);
$("label[for='" + me.attr('id') + "']").addClass("animate-label");
});
$('.input-group input').blur(function () {
me = $(this);
if (me.val() == "") {
$("label[for='" + me.attr('id') + "']").removeClass("animate-label");
}
});
});
</script>
</body>
</html>