-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_management.php
70 lines (60 loc) · 2.47 KB
/
user_management.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
<?php
// Define page variables
$page = 'user_management';
$page_title = 'User Management';
$back_url = 'admin_dashboard.php';
include 'templates/admin_header.php';
require_once 'db_connection.php';
// Handle search query
$search_query = isset($_GET['search']) ? $conn->real_escape_string($_GET['search']) : '';
// SQL query to retrieve all users or search results
$sql = "SELECT id, username, name, email, role FROM users WHERE username LIKE '%$search_query%' OR name LIKE '%$search_query%'";
$result = $conn->query($sql);
if ($result === false) {
die("Error executing query: " . $conn->error);
}
?>
<div class='dashboard-content'>
<h1 class="page-title"><?php echo $page_title; ?></h1>
<!-- Search Form -->
<form action='user_management.php' method='get' class="search-form">
<input type='text' name='search' placeholder='Search by username or name' value='<?php echo htmlspecialchars($search_query); ?>'>
<button type='submit' class="button search-button">Search</button>
</form>
<!-- User Table -->
<?php if ($result->num_rows > 0) { ?>
<div class="table-responsive">
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['role']; ?></td>
<td class="action-buttons">
<a href="edit_user.php?id=<?php echo $row['id']; ?>" class="button edit-button">Edit</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } else { ?>
<p class="no-results">No users found.</p>
<?php } ?>
<!-- Add New User Button -->
<a href="add_user.php" class="button add-button">Add New User</a>
</div>
<?php include 'templates/admin_footer.php'; ?>