-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_delete_student.php
More file actions
64 lines (56 loc) · 2.39 KB
/
admin_delete_student.php
File metadata and controls
64 lines (56 loc) · 2.39 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
<?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'];
// First, delete rows from apath_pickup where s_id is referenced
$delete_pickup_sql = "DELETE FROM apath_pickup WHERE s_id='$s_id'";
mysqli_query($dbc, $delete_pickup_sql); // Execute deletion of dependent rows
// Then, delete the student from apath_student
$delete_student_sql = "DELETE FROM apath_student WHERE s_id='$s_id'";
mysqli_query($dbc, $delete_student_sql); // Delete the student record
// Now, delete the user from apath_users
$delete_user_sql = "DELETE FROM apath_users WHERE id='$s_id'"; // Assuming the id in apath_users is the same as s_id
if (mysqli_query($dbc, $delete_user_sql)) {
ob_start(); // Start output buffering
echo "Student and related records deleted successfully";
header("Location: admin_manage_s.php"); // Redirect to manage students page
ob_end_flush(); // Flush the output buffer and send the headers
exit();
} else {
echo "Error: " . $delete_user_sql . "<br>" . mysqli_error($dbc);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Delete 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>Delete Student</h2>
<p>Are you sure you want to delete the following student?</p>
<p>First Name: <?php echo htmlspecialchars($student['first_name'] ?? ''); ?></p>
<p>Last Name: <?php echo htmlspecialchars($student['last_name'] ?? ''); ?></p>
<p>Phone: <?php echo htmlspecialchars($student['phone'] ?? ''); ?></p>
<p>Email: <?php echo htmlspecialchars($student['email'] ?? ''); ?></p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . $s_id; ?>" method="POST">
<button type="submit">Confirm Delete</button>
</form>
<a href="admin_manage_s.php">Cancel</a>
</div>
</body>
</html>