-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage_users.php
73 lines (67 loc) · 2.14 KB
/
manage_users.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
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
<?php
// Database Connection
$conn = new mysqli("localhost", "root", "", "project");
// Check Connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Delete User (if requested)
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$query = "DELETE FROM users WHERE id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo "User deleted successfully!";
} else {
echo "Error: " . $stmt->error;
}
}
// Fetch All Users
$query = "SELECT * FROM users";
$result = $conn->query($query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Manage Users</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
table, th, td { border: 1px solid #ddd; }
th, td { padding: 10px; text-align: left; }
th { background-color: #f2f2f2; }
.btn { padding: 5px 10px; text-decoration: none; color: white; border-radius: 4px; }
.btn-delete { background-color: red; }
.btn-edit { background-color: red; }
</style>
</head>
<body>
<h2>Manage Users</h2>
<table>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Actions</th>
</tr>
<?php if ($result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td>
<a href="edit_users.php?id=<?php echo $row['id']; ?>" class="btn btn-edit">Edit</a>
<a href="manage_users.php?delete=<?php echo $row['id']; ?>" class="btn btn-delete" onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="4">No users found!</td>
</tr>
<?php endif; ?>
</table>
</body>
</html>