12
This commit is contained in:
parent
a0df7edb65
commit
eecf468a95
13
admin.php
13
admin.php
@ -5,17 +5,18 @@ require_once __DIR__ . '/db/config.php';
|
||||
$pdo = db();
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: index.php');
|
||||
header('Location: /admin_login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
|
||||
$stmt = $pdo->prepare("SELECT * FROM admin_users WHERE id = ?");
|
||||
$stmt->execute([$_SESSION['user_id']]);
|
||||
$user = $stmt->fetch();
|
||||
$admin = $stmt->fetch();
|
||||
$user = $admin; $user["role"] = "admin";
|
||||
|
||||
if (!$user) {
|
||||
if (!$admin) {
|
||||
session_destroy();
|
||||
header('Location: index.php?error=user_not_found');
|
||||
header('Location: /admin_login.php?error=user_not_found');
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$id = $_POST['id'];
|
||||
if ($id != $_SESSION['user_id']) {
|
||||
// Foreign keys are ON DELETE CASCADE, so this is safe
|
||||
$stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
|
||||
$stmt = $pdo->prepare("DELETE FROM admin_users WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
header('Location: admin.php?action=users');
|
||||
|
||||
BIN
assets/pasted-20260322-121049-fde8d6eb.png
Normal file
BIN
assets/pasted-20260322-121049-fde8d6eb.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 115 KiB |
Loading…
x
Reference in New Issue
Block a user