34915-vm/admin_users.php
2025-10-14 07:40:18 +00:00

58 lines
2.2 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
require_once 'includes/header.php';
// Protect the page: redirect if user is not logged in
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
// Fetch all users from the database
$pdo = db();
$stmt = $pdo->query("SELECT id, name, email, created_at FROM users ORDER BY created_at DESC");
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<main class="container mt-5 pt-5">
<div class="card">
<div class="card-header">
<h1 class="h2">Registered Users</h1>
</div>
<div class="card-body">
<p>This table displays all users who have registered on the platform.</p>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-dark">
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Registration Date</th>
</tr>
</thead>
<tbody>
<?php if (empty($users)): ?>
<tr>
<td colspan="4" class="text-center">No users found.</td>
</tr>
<?php else: ?>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo htmlspecialchars($user['id']); ?></td>
<td><?php echo htmlspecialchars($user['name']); ?></td>
<td><?php echo htmlspecialchars($user['email']); ?></td>
<td><?php echo htmlspecialchars(date('F j, Y, g:i a', strtotime($user['created_at']))); ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</main>
<?php require_once 'includes/footer.php'; ?>