-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex2.php
147 lines (101 loc) · 4.63 KB
/
index2.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
<?php
require "includes/db_connect.php";
require "includes/auth.php";
// error handler function
function myErrorHandler($errno, $errstr){
echo "<b>Error:</b> [$errno] $errstr";
}
// set error handler function
set_error_handler("myErrorHandler");
// Initialize the session.
session_start();
// Defining the variables in the global
$name = ''; $email = ''; $phone_no = ''; $crew = ''; $to = ''; $time = ''; $date = ''; $airline = '';
$fare = ''; $seat = ''; $message = '';
// Check if a new form is submitted and its not empty, then add it to the database
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (isset($_POST['save'])){
require "includes/display_upload.php";
$customer_name = trim(htmlspecialchars($_POST['name']));
$booking_date = trim($_POST['date']);
$booking_time = trim($_POST['time']);
$location_to = trim($_POST['to']);
$customer_message = trim(htmlspecialchars($_POST['message']));
$phone_no = trim(htmlspecialchars($_POST['phone_no']));
$email = trim(htmlspecialchars($_POST['email']));
$seat = trim($_POST['seat']);
$airline = trim($_POST['airline']);
$fare = trim($_POST['fare']);
$crew = trim($_POST['crew']);
if (!empty($customer_name) && !empty($booking_date) && !empty($booking_time) && !empty($location_to) && !empty($phone_no) && !empty($email) && !empty($seat)
&& !empty($airline) && !empty($fare) && !empty($crew)){
// makes the message field "null" if not filled
if ($customer_message == ''){
$customer_message = null;
}
// connect to the database server
$conn = connectDB();
// inserts the data into the database server
$sql = "INSERT INTO passengers_record (image_file, customer_name, email, phone_no, crew, location_to, booking_time, booking_date, airline, fare, seat, customer_message)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
// Prepares an SQL statement for execution
$stmt = mysqli_prepare($conn, $sql);
if ($stmt === false){
echo mysqli_error($conn);
} else {
// i - integer, d - double, s - string
// Bind variables for the parameter markers in the SQL statement prepared
mysqli_stmt_bind_param($stmt, "ssssssssssss", $filename, $customer_name, $email, $phone_no, $crew, $location_to, $booking_time, $booking_date, $airline, $fare, $seat, $customer_message);
// Executes a prepared statement
$results = mysqli_stmt_execute($stmt);
// checking for errors, if none, then redirect the user to the new article page
if ($results === false){
echo mysqli_stmt_error($stmt);
} else {
//Returns the value generated for an AUTO_INCREMENT column by the last query
$id = mysqli_insert_id($conn);
// it is more advisable to use absolute paths below than relative path
header("Location: http://localhost/flight_booking-app/customer_data.php?id=$id");
exit;
}
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Flight Booking App</title>
<link rel="stylesheet" href="./stylings/style.css">
</head>
<body>
<h1>AeroLux Airline Booking Form</h1>
<div class="container">
<form method="POST" id="booking" enctype="multipart/form-data">
<?php require "./includes/the_form.php" ?>
<br>
<div>
<label for="file">Image File</label>
<!--if "multiple" attribute is added below, it will allow for multiple uploads-->
<input type="file" name="file" id="file">
</div>
<br> <br>
<div align="center">
<input type="submit" id="home_submit" value="Submit" name="save">
<input type="reset" id="home_clear" value="Clear Form">
</div>
</form>
<!-- Working with Sessions-->
<center>
<?php if (isLoggedIn()) : ?>
<p>You are logged in. <a href="logout.php">Logout</a></p>
<!-- only logged in user should access this link below-->
<a href="admin_page.php" target="_blank">Go To Database</a>
<?php else : ?>
<p>Are you an admin? If yes, <a href="login.php" target="_blank">Login</a>!</p>
<?php endif; ?>
</center>
</div>
</body>
</html>