-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_admin.php
More file actions
34 lines (29 loc) · 1.01 KB
/
delete_admin.php
File metadata and controls
34 lines (29 loc) · 1.01 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
<?php
session_start();
include 'db.php';
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: splash.php");
exit;
}
if (isset($_GET['id'])) {
$adminId = (int) $_GET['id'];
$currentAdminId = $_SESSION['admin_id'];
try {
// Delete the admin account from the database
$sql = "DELETE FROM admin_accounts WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->execute([$adminId]);
// If the deleted admin is the current user, log them out
if ($adminId === $currentAdminId) {
session_destroy(); // Destroy all session data
header("Location: login.php?message=Your account has been deleted");
exit;
}
// Otherwise, redirect back to the staff page with a success message
header("Location: admin_staff.php?message=Admin deleted successfully.");
exit;
} catch (PDOException $e) {
echo "Error deleting admin: " . $e->getMessage();
}
}
?>