-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentflight.php
380 lines (288 loc) · 9.24 KB
/
studentflight.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
session_start();
?>
<?php
$id =$_SESSION['id'];
$pickup = $info = $name =$flightcomment = $date = $time = $fnum = $laname = $ldate = $ltime = $bluggage =$sluggage = $afnum="";
$pickupErr = $infoErr = $nameErr = $dateErr = $timeErr = $fnumErr = $lanameErr = $ldateErr = $ltimeErr = $bluggageErr =$sluggageErr =$flightcommentErr =$afnumErr="";
$flag=0;
include("project3connection.php");
$id=$_SESSION['id'];
$qs = "SELECT *, DATE_FORMAT(aDate, '%m/%d/%Y')as aDate, DATE_FORMAT(lDate, '%m/%d/%Y')as lDate FROM student WHERE s_id = '$id'";
$query = mysqli_query($dbc,$qs);
$num = mysqli_num_rows($query);
if($num!=0){
while($row = mysqli_fetch_array($query)){
// $id = $row['id'];
$pickup = $row['pickup'];
$info = $row['flightInfo'];
$afnum = $row['aflightnum'];
$name = $row['aairline'];
$date = $row['aDate'];
$time = $row['aTime'];
$fnum = $row['lflightnum'];
$laname = $row['lairline'];
$ldate = $row['lDate'];
$ltime = $row['lTime'];
$sluggage = $row['smalllug'];
$bluggage = $row['biglug'];
$flightcomment = $row['flightComment'];
}
}
?>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
// pickup filed
if(empty($_POST["pickup"])){ // if empty
$pickupErr = "Pickup is required";
$flag=1;
}
else{
$pickup = test_input($_POST["pickup"]);
}
// info filed
if(empty($_POST["info"])){ // if empty
$infoErr = "Info is required";
$flag=1;
}
else{
$info = test_input($_POST["info"]);
}
// arrival flight
if(empty($_POST["afnum"])){ // if empty
$afnumErr = "arriaval flight is required";
$flag=1;
}
else{
$afnum = test_input($_POST["afnum"]);
}
// Airline name
if(empty($_POST["name"])){ // if empty
$nameErr = "name is required";
$flag=1;
}
else{
$name = test_input($_POST["name"]);
}
// Airline date
if(empty($_POST["date"])){ // if empty
$dateErr = "array date is required";
$flag=1;
}
else{
$date = test_input($_POST["date"]);
if(!preg_match("/^(0[1-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])\/\d{4}$/",$date)){
$dateErr ="Wrong formate, please enter again!";
$flag =1;
}
}
// arrival time
if(empty($_POST["time"])){ // if empty
$timeErr = "arrival time is required";
$flag=1;
}
else{
$time = test_input($_POST["time"]);
if(!preg_match("/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/",$time)){
$timeErr ="Wrong formate, please enter again!";
$flag =1;
}
}
// leave flight number
if(empty($_POST["fnum"])){ // if empty
$fnumErr = "Leaving flight is required";
$flag=1;
}
else{
$fnum = test_input($_POST["fnum"]);
}
// Leaving name
if(empty($_POST["laname"])){ // if empty
$lanameErr = "Leaving flight name is required";
$flag=1;
}
else{
$laname = test_input($_POST["laname"]);
}
// Leave date
if(empty($_POST["ldate"])){ // if empty
$ldateErr = "leave date is required";
$flag=1;
}
else{
$ldate = test_input($_POST["ldate"]);
if(!preg_match("/^(0[1-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])\/\d{4}$/",$ldate)){
$ldateErr ="Wrong formate, please enter again!";
$flag =1;
}
}
// leave time
if(empty($_POST["ltime"])){ // if empty
$ltimeErr = "leave time is required";
$flag=1;
}
else{
$ltime = test_input($_POST["ltime"]);
if(!preg_match("/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/",$ltime)){
$ltimeErr ="Wrong formate, please enter again!";
$flag =1;
}
}
// big luggage
if(empty($_POST["bluggage"])){ // if empty
$bluggageErr = "Big luggage is required";
$flag=1;
}
else{
$bluggage = test_input($_POST["bluggage"]);
}
// Small luggage
if(empty($_POST["sluggage"])){ // if empty
$sluggageErr = "Small luggage is required";
$flag=1;
}
else{
$sluggage = test_input($_POST["sluggage"]);
}
$flightcomment = test_input($_POST["flightcomment"]);
if($flag==0){
// if there is not red flag, we are ready to make connect to the database
include("project3connection.php");
$qs = "SELECT * FROM student WHERE s_id = '$id'";
$query = mysqli_query($dbc,$qs);
$num = mysqli_num_rows($query);
if($num!=0){
$sq1 = "UPDATE student SET
pickup = '$pickup',
flightInfo = '$info',
aairline = '$name',
aflightnum = '$fnum',
aDate = STR_TO_DATE('$date', '%m/%d/%Y'),
aTime = '$time',
lflightnum = '$afnum',
lairline = '$laname',
lDate = STR_TO_DATE('$ldate', '%m/%d/%Y'),
lTime = '$ltime',
smalllug = '$sluggage ',
biglug = '$bluggage',
flightComment = '$flightcomment '
WHERE s_id = '$id'";
}
else{
$sq1 = "INSERT INTO student(s_id, pickup, flightInfo, aairline, aflightnum, aDate, aTime, lflightnum, lairline, lDate, lTime, smalllug, biglug, flightComment)
VALUES ('$id', '$pickup', '$info', '$name', '$fnum', STR_TO_DATE('$date', '%m/%d/%Y'), '$time', '$afnum', '$laname', STR_TO_DATE('$ldate', '%m/%d/%Y'), '$ltime', '$sluggage', '$bluggage', '$flightcomment')";
}
mysqli_query($dbc,$sq1);
$registered = mysqli_affected_rows($dbc);
echo $registered." row has/have been affected.<br>";
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<html>
<head>
<title>Flight Information</title>
<style>
.error{
color: red;
}
</style>
</head>
<body>
<?php
include("studntnav.php");
?>
<h2 style= "color: blue"> Student Flight Inforation</h2>
<div style ="border :solid;padding:1.1em">
<form action ="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"method ="post" >
Do you need airport pickup?<span class = "error">*</span>
<input type="radio" name="pickup" <?php if (isset($pickup)&& $pickup =="yes") echo"checked";?> value="yes" > Yes
<input type="radio" name="pickup" <?php if (isset($pickup)&& $pickup =="no") echo"checked";?> value="no" > No
<span class = "error">
<?php echo $pickupErr; ?>
</span>
<br>
Do you have the flight information?<span class = "error">*</span>
<input type="radio" name="info" <?php if (isset($info)&& $info =="yes") echo"checked";?> value="yes" > Yes
<input type="radio" name="info" <?php if (isset($info)&& $info =="no") echo"checked";?> value="no" > No
<span class = "error">
<?php echo $infoErr; ?>
</span>
<br>
if yes, arriving Atlanta - Flight Number
<span class = "error">*</span><input type ="text" name= "afnum" value = "<?php echo$afnum;?>">
<span class = "error">
<?php echo $afnumErr; ?>
</span>
<br>
Arriving Atlanta - Airline Name
<span class = "error">*</span><input type ="text" name= "name" value = "<?php echo$name;?>">
<span class = "error">
<?php echo $nameErr; ?>
</span>
<br>
Arriving Atlanta - Date
<span class = "error">*</span><input type ="text" name= "date" value = "<?php echo$date;?>">
(Use mm/dd/yyyy formate)
<span class = "error">
<?php echo $dateErr; ?>
</span>
<br>
Arriving Atlanta - Time
<span class = "error">*</span><input type ="text" name= "time" value = "<?php echo$time;?>">
(Please use format hh:mm such as 17:20 or 08:15)
<span class = "error">
<?php echo $timeErr; ?>
</span>
<br>
Leaving - Flight Number:
<span class = "error">*</span><input type ="text" name= "fnum" value = "<?php echo$fnum;?>">
<span class = "error">
<?php echo $fnumErr; ?>
</span>
<br>
Leaving - Airline Name:
<span class = "error">*</span><input type ="text" name= "laname" value = "<?php echo$laname;?>">
<span class = "error">
<?php echo $lanameErr; ?>
</span>
<br>
Leaving - Date
<span class = "error">*</span><input type ="text" name= "ldate" value = "<?php echo$ldate;?>">
(Use mm/dd/yyy formate)
<span class = "error">
<?php echo $ldateErr; ?>
</span>
<br>
Leaving - Time
<span class = "error">*</span><input type ="text" name= "ltime" value = "<?php echo$ltime;?>">
(Please use format hh:mm such as 17:20 or 08:15)
<span class = "error">
<?php echo $ltimeErr; ?>
</span>
<br>
How many piece of big luggage
<span class = "error">*</span><input type ="text" name= "bluggage" value = "<?php echo$bluggage;?>">
<span class = "error">
<?php echo $bluggageErr; ?>
</span>
<br>
How many piece of small luggage
<span class = "error">*</span><input type ="text" name= "sluggage" value = "<?php echo$sluggage;?>">
<span class = "error">
<?php echo $sluggageErr; ?>
</span>
<br>
</div>
Any Comment:<br>
<textarea name ="flightcomment" rows ="5" cols="40"> <?php echo $flightcomment;?></textarea> <br><br>
<input type = "submit" name = "submit" value="submit">
<br>
</form>
</body>
</html>