-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_edit_student.php
More file actions
165 lines (151 loc) · 7.87 KB
/
admin_edit_student.php
File metadata and controls
165 lines (151 loc) · 7.87 KB
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
<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] != 0) { // Assuming user_type 0 is for admin
header("Location: login.php");
exit();
}
include "connection.php";
if (isset($_GET['id'])) {
$s_id = $_GET['id'];
$query = "SELECT * FROM apath_student WHERE s_id='$s_id'";
$result = mysqli_query($dbc, $query);
$student = mysqli_fetch_assoc($result);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = test_input($_POST["first_name"]);
$last_name = test_input($_POST["last_name"]);
$phone = test_input($_POST["phone"]);
$email = test_input($_POST["email"]);
$gender = test_input($_POST["gender"]);
$flight_info = test_input($_POST["flight_info"]);
$flight_airline = test_input($_POST["flight_airline"]);
// Check for empty flight_date and set it to NULL if empty
$flight_date = !empty($_POST["flight_date"]) ? test_input($_POST["flight_date"]) : NULL;
$flight_time = test_input($_POST["flight_time"]);
$c_flight_info = test_input($_POST["c_flight_info"]);
$c_flight_airline = test_input($_POST["c_flight_airline"]);
// Check for empty c_flight_date and set it to NULL if empty
$c_flight_date = !empty($_POST["c_flight_date"]) ? test_input($_POST["c_flight_date"]) : NULL;
$c_flight_time = test_input($_POST["c_flight_time"]);
// Check for empty luggage values and set them to NULL if empty
$big_luggage = !empty($_POST["big_luggage"]) ? test_input($_POST["big_luggage"]) : NULL;
$small_luggage = !empty($_POST["small_luggage"]) ? test_input($_POST["small_luggage"]) : NULL;
$sql = "UPDATE apath_student SET
first_name='$first_name',
last_name='$last_name',
phone='$phone',
email='$email',
gender='$gender',
flight_info='$flight_info',
flight_airline='$flight_airline',
flight_date=" . ($flight_date ? "'$flight_date'" : "NULL") . ",
flight_time='$flight_time',
c_flight_info='$c_flight_info',
c_flight_airline='$c_flight_airline',
c_flight_date=" . ($c_flight_date ? "'$c_flight_date'" : "NULL") . ",
c_flight_time='$c_flight_time',
big_luggage=" . ($big_luggage !== NULL ? "'$big_luggage'" : "NULL") . ",
small_luggage=" . ($small_luggage !== NULL ? "'$small_luggage'" : "NULL") . "
WHERE s_id='$s_id'";
if (mysqli_query($dbc, $sql)) {
ob_start(); // Start output buffering
echo "Student information updated successfully";
header("Location: admin_manage_s.php");
ob_end_flush(); // Flush the output buffer and send the headers
exit();
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($dbc);
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Student - APATH</title>
<link rel="stylesheet" href="apath.css">
</head>
<body>
<div class="container">
<h1>APATH</h1>
<?php
$current_page = basename($_SERVER['PHP_SELF']);
include "a_nav.php";
?>
<h2>Edit Student Information</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . $s_id; ?>" method="POST">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" id="first_name" name="first_name" value="<?php echo htmlspecialchars($student['first_name'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" id="last_name" name="last_name" value="<?php echo htmlspecialchars($student['last_name'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" value="<?php echo htmlspecialchars($student['phone'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" value="<?php echo htmlspecialchars($student['email'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="gender">Gender:</label>
<input type="text" id="gender" name="gender" value="<?php echo htmlspecialchars($student['gender'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="flight_info">Flight Info:</label>
<input type="text" id="flight_info" name="flight_info" value="<?php echo htmlspecialchars($student['flight_info'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="flight_airline">Flight Airline:</label>
<input type="text" id="flight_airline" name="flight_airline" value="<?php echo htmlspecialchars($student['flight_airline'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="flight_date">Flight Date:</label>
<input type="date" id="flight_date" name="flight_date" value="<?php echo htmlspecialchars($student['flight_date'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="flight_time">Flight Time:</label>
<input type="time" id="flight_time" name="flight_time" value="<?php echo htmlspecialchars($student['flight_time'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="c_flight_info">Connecting Flight Info:</label>
<input type="text" id="c_flight_info" name="c_flight_info" value="<?php echo htmlspecialchars($student['c_flight_info'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="c_flight_airline">Connecting Flight Airline:</label>
<input type="text" id="c_flight_airline" name="c_flight_airline" value="<?php echo htmlspecialchars($student['c_flight_airline'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="c_flight_date">Connecting Flight Date:</label>
<input type="date" id="c_flight_date" name="c_flight_date" value="<?php echo htmlspecialchars($student['c_flight_date'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="c_flight_time">Connecting Flight Time:</label>
<input type="time" id="c_flight_time" name="c_flight_time" value="<?php echo htmlspecialchars($student['c_flight_time'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="big_luggage">Big Luggage:</label>
<input type="number" id="big_luggage" name="big_luggage" value="<?php echo htmlspecialchars($student['big_luggage'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="small_luggage">Small Luggage:</label>
<input type="number" id="small_luggage" name="small_luggage" value="<?php echo htmlspecialchars($student['small_luggage'] ?? ''); ?>">
</div>
<button type="submit">Update</button>
</form>
<div class="footer">
<p><a href="#">Covid Information and Guidelines</a></p>
</div>
</div>
</body>
</html>