-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.php
More file actions
80 lines (71 loc) · 2.19 KB
/
Copy pathuser.php
File metadata and controls
80 lines (71 loc) · 2.19 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
<?php
session_start();
if (!isset($_SESSION["email"]) || $_SESSION["user_type"] != "admin") {
header("Location: login.php");
exit();
}
$conn = new mysqli("localhost", "root", "", "dbms");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Handle user deletion
if (isset($_GET["user_id"])) {
$user_id = intval($_GET["user_id"]);
$delete_query = "DELETE FROM user WHERE user_id = ?";
$stmt = $conn->prepare($delete_query);
$stmt->bind_param("i", $user_id);
if ($stmt->execute()) {
$message = "User deleted successfully!";
} else {
$message = "Error deleting user: " . $conn->error;
}
$stmt->close();
}
// Fetch all users
$sql = "SELECT * FROM user";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<title>Manage Users</title>
</head>
<body>
<div class="sidebar">
<h2 class="menu" style="color:#3BABF6">ADMIN MENU</h2>
<a href="admin_dashboard.php">Admin Dashboard</a>
<a href="add_user.php">Add User</a>
<a href="books_admin.php">Manage Books</a>
<a href="admin_cart.php">View Cart</a>
<a href="orders.php">View Orders</a>
<form method="POST" action="admin_dashboard.php">
<button type="submit" name="signout" class="button signout">Sign Out</button>
</form>
</div>
<h1>Manage Users</h1>
<div class="container">
<table class="table">
<tr>
<th>User ID</th>
<th>Email</th>
<th>Action</th>
</tr>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row["user_id"]); ?></td>
<td><?php echo htmlspecialchars($row["email"]); ?></td>
<td>
<a href="?user_id=<?php echo $row[
"user_id"
]; ?>" class="button" onclick="return confirm('Are you sure you want to delete this book?')">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
</body>
</html>
<?php $conn->close();
?>