-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_user_delete.php
47 lines (40 loc) · 1.28 KB
/
manage_user_delete.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
<?php
// delete_user.php
// Include necessary files and initialize the session
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();
require_once "./connect_db.php"; // Connect to your database
// Check if the admin is logged in
if (!isset($_SESSION['admin_username'])) {
echo "Unauthorized access. Please log in as an admin.";
header("Location: ./admin.php");
exit();
}
// Get the user ID from the URL
$user_id = isset($_GET['user_id']) ? $_GET['user_id'] : null;
$tournament_id = isset($_GET['tournament_id']) ? $_GET['tournament_id'] : null;
// Check if a valid user ID is provided
if ($user_id === null) {
echo "Invalid user ID.";
exit();
}
if ($tournament_id === null) {
echo "Invalid tournament ID.";
exit();
}
// Delete related entries in league_table
$delete_related_sql = "DELETE FROM league_table WHERE user_id = $user_id";
if ($conn->query($delete_related_sql) === FALSE) {
echo "Error deleting related entries: " . $conn->error;
exit();
}
// Now, delete the user
$delete_user_sql = "DELETE FROM registration WHERE user_id = $user_id";
if ($conn->query($delete_user_sql) === TRUE) {
header("Location: manage_users.php?tournament_id=$tournament_id");
} else {
echo "Error deleting user: " . $conn->error;
}
$conn->close();
?>