<?php sessionstart(); if (!isset($SESSION['username'])… · The Chat Archive
Explore / Programming <?php sessionstart(); if (!isset($SESSION['username']) $SESSION['role'] !== 'admin') {… Save Share Download ▾ Report
<div class="top-navbar mb-4">
<span>Welcome, <?=htmlspecialchars($_SESSION['username'])?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-sm">Logout <i class="bi bi-box-arrow-right"></i></a>
</div>
<!-- Stats Cards -->
<div class="row g-4 mb-5">
<div class="col-md-3">
<div class="stat-card">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#4ade80,#16a34a);">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#facc15,#ca8a04);">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#ef4444,#b91c1c);">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</div>
</div>
</div>
<!-- Recent Borrow Records -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Recent Borrow Records</h3>
<div class="table-responsive shadow rounded">
<table id="recentBorrowsTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th><th>User</th><th>Book</th><th>Borrow Date</th><th>Due Date</th><th>Return Date</th><th>Fine</th>
</tr>
</thead>
<tbody>
<?php foreach($recentBorrows as $r): ?>
<tr>
<td><?= $r['id'] ?></td>
<td><?= htmlspecialchars($r['username']) ?></td>
<td><?= htmlspecialchars($r['title']) ?></td>
<td><?= $r['borrow_date'] ?></td>
<td><?= $r['due_date'] ?></td>
<td><?= $r['return_date'] ?? '-' ?></td>
<td><?= $r['fine'] ? '$'.number_format($r['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">View All Borrow Records</a>
</section>
<!-- Users Section -->
<section>
<h3 class="fw-semibold mb-4">Users</h3>
<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#addUserModal">
<i class="bi bi-person-plus-fill"></i> Add User
</button>
<div class="table-responsive shadow rounded" style="max-height: 400px; overflow-y: auto;">
<table id="usersTable" class="table table-hover align-middle">
<thead class="table-secondary">
<tr>
<th>ID</th><th>Username</th><th>Role</th><th>Created At</th><th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): ?>
<tr>
<td><?= $u['id'] ?></td>
<td><?= htmlspecialchars($u['username']) ?></td>
<td>
<?php if ($u['role'] === 'admin'): ?>
<span class="badge badge-role-admin">Admin</span>
<?php else: ?>
<span class="badge badge-role-member">Member</span>
<?php endif; ?>
</td>
<td><?= $u['created_at'] ?></td>
<td>
<?php if ($u['id'] != 1): ?>
<form method="post" style="display:inline-block" onsubmit="return confirm('Delete user <?=htmlspecialchars(addslashes($u['username']))?>?');">
<input type="hidden" name="delete_user" value="<?= $u['id'] ?>" />
<button type="submit" class="btn btn-sm btn-danger" title="Delete User"><i class="bi bi-trash-fill"></i></button>
</form>
<?php else: ?>
<span class="text-muted fst-italic">Protected</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</section>
<hr class="my-5"/>
<!-- Books Section Summary -->
<section>
<h3 class="fw-semibold">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg">
<i class="bi bi-book-fill"></i> Manage Books
</a>
</section>
Assistant2025-04-23 20:23 UTC Copy response
Assistant2025-04-23 20:24 UTC Copy response
Your provided code is a standalone manage_users.php page for user management in the admin panel, handling add and delete user functionality, with feedback and validation.
Assistant2025-04-23 20:26 UTC Copy response
Assistant2025-04-23 20:27 UTC Copy response
Got it! You have:
A full page which manages users (add/delete, list, etc).
Assistant2025-04-23 20:28 UTC Copy response
give me a best admin_dashboard whatever i sais
Assistant2025-04-23 20:29 UTC Copy response
Assistant2025-04-23 20:33 UTC Copy response
Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password_hash' in 'field list' in C:\xampp\htdocs\library_lms\users.php:39 Stack trace: #0 C:\xampp\htdocs\library_lms\users.php(39): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\library_lms\users.php on line 39
Assistant2025-04-23 20:36 UTC Copy response
The error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password_hash' in 'field list'
means that in your users table, the column password_hash does not exist. Most likely your password column is named differently (commonly just password).
How to fix
Option 1: Change your database
If you want to use the column name password_hash, then you need to rename (or add) that column in your database table. For example, run this SQL in your MySQL client:
Assistant2025-04-23 20:37 UTC Copy response
Assistant2025-04-23 20:39 UTC Copy response
Assistant2025-04-23 20:43 UTC Copy response
Table showing 5 most recent borrow records including user, book, borrow and return dates, and fines.
ID User Book Borrow Date Due Date Return Date Fine
5 aryan Pride and Prejudice 2025-04-23 2025-05-07 - -
2 aryan Dune 2025-04-21 2025-05-05 2025-04-21 -
why coming like this numbering
Assistant2025-04-23 20:45 UTC Copy response
Table showing 5 most recent borrow records including user, book, borrow and return dates, and fines.
ID User Book Borrow Date Due Date Return Date Fine
5 aryan Pride and Prejudice 2025-04-23 2025-05-07 - -
2 aryan Dune 2025-04-21 2025-05-05 2025-04-21 -
see id table why 2 and 5 numbering is not proper
Assistant2025-04-23 20:46 UTC Copy response
The numbering you're seeing in the ID column (5, then 2) is reflecting the actual values from your database rows — but the primary key or identifier of each borrow record.
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 13 (26 messages)
Language en
Conversation date Apr 23, 2025
Added to archive Nov 16, 2026
ID 01m7h42ma0kxy0rfbdp617wvzvSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 3188c76dfc7d9506671102d95d7fb998
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
Sure! To integrate your user.php logic with this admin dashboard page, we need to:
Ensure the add user and delete user functionalities from user.php are correctly handled in this dashboard PHP file.
Typically, user.php handles user CRUD operations. Since your current dashboard page already has placeholders for add/delete user logic (commented as // POST handlers (your add/delete user logic goes here)), the integration mostly comes down to copying the relevant user management code (POST handlers) into this dashboard page.
Confirm that after user creation/deletion, the page reloads, showing updated users.
What I will provide:
Add user handler (POST action).
Delete user handler (POST action).
Minor fixes like redirecting or showing feedback (optional, but recommended).
Step 1: Add handlers for add/delete users
I assume your user.php has similar add/delete user code, e.g.:
// Example add user:
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_user') {
// Validate and insert user
}
// Example delete user:
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_user'])) {
// Delete user where id = $_POST['delete_user']
}
Step 2: Add these handlers to your dashboard PHP (before fetching & displaying data):
Paste this near the top after PDO $pdo initialization.
// Handle Add User
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_user') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$role = $_POST['role'] ?? 'member';
$errors = [];
// Simple validation
if ($username === '') {
$errors[] = "Username is required.";
}
if ($password === '') {
$errors[] = "Password is required.";
}
if (!in_array($role, ['admin', 'member'])) {
$errors[] = "Invalid role selected.";
}
if (empty($errors)) {
// Check if username already exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetch()) {
$errors[] = "Username already taken.";
} else {
// Insert new user
$hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, password, role, created_at) VALUES (?, ?, ?, NOW())");
$stmt->execute([$username, $hash, $role]);
// Redirect to avoid resubmission & show updated list
header("Location: ".$_SERVER['PHP_SELF']);
exit;
}
}
}
// Handle Delete User
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_user'])) {
$deleteUserId = (int)$_POST['delete_user'];
// Prevent deleting protected user id = 1
if ($deleteUserId !== 1) {
$stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
$stmt->execute([$deleteUserId]);
// Redirect after deletion to avoid resubmission & show refresh
header("Location: ".$_SERVER['PHP_SELF']);
exit;
}
}
Step 3: Optionally show errors in the Add User Modal if validation fails
To do this, pass errors to the HTML, e.g.,
At the top define errors array , e.g.:
$errors = $errors ?? [];
Then, inside your "Add User" modal form, somewhere above inputs, you can add:
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<ul class="mb-0">
<?php foreach ($errors as $error): ?>
<li><?= htmlspecialchars($error) ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Also, if you want to re-open the modal when errors occurred, add this script near the bottom inside <script>:
<?php if (!empty($errors)): ?>
var addUserModal = new bootstrap.Modal(document.getElementById('addUserModal'));
addUserModal.show();
<?php endif; ?>
Summary:
Your admin dashboard PHP page will handle user add/delete directly.
Fetch updated users after those actions, no need for separate user.php page unless user management requires a separate full page.
The integrated code will be self-contained in this single dashboard page.
If you want, I can provide you a full updated code version with all these integrated. Just ask!
<!-- Display Feedback -->
<?php if (isset($_SESSION['error'])): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?=htmlspecialchars($_SESSION['error'])?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['success'])): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?=htmlspecialchars($_SESSION['success'])?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php unset($_SESSION['success']); ?>
<?php endif; ?>
<!-- Add User Button -->
<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#addUserModal">
<i class="bi bi-person-plus-fill"></i> Add User
</button>
<!-- Users Table -->
<div class="table-responsive shadow rounded">
<table id="usersTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Username</th>
<th>Role</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= (int)$user['id'] ?></td>
<td><?= htmlspecialchars($user['username']) ?></td>
<td>
<?php if ($user['role'] === 'admin'): ?>
<span class="badge badge-admin">Admin</span>
<?php else: ?>
<span class="badge badge-member">Member</span>
<?php endif; ?>
</td>
<td><?= htmlspecialchars($user['created_at']) ?></td>
<td>
<?php if ($user['id'] !== 1): ?>
<form method="post" class="d-inline" onsubmit="return confirm('Are you sure you want to delete user <?=htmlspecialchars(addslashes($user['username']))?>?');">
<input type="hidden" name="delete_user" value="<?= (int)$user['id'] ?>" />
<button type="submit" class="btn btn-sm btn-danger" title="Delete User"><i class="bi bi-trash-fill"></i></button>
</form>
<?php else: ?>
<span class="text-muted">Protected</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- Add User Modal -->
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="addUserModalLabel" aria-hidden="true" style="--bs-modal-width:400px;">
<div class="modal-dialog">
<form method="post" class="modal-content needs-validation" novalidate>
<input type="hidden" name="action" value="add_user" />
<div class="modal-header">
<h5 class="modal-title" id="addUserModalLabel">Add New User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="add-username" class="form-label">Username *</label>
<input type="text" name="username" id="add-username" class="form-control" required />
<div class="invalid-feedback">Please enter a username.</div>
</div>
<div class="mb-3">
<label for="add-password" class="form-label">Password *</label>
<input type="password" name="password" id="add-password" class="form-control" required />
<div class="invalid-feedback">Please enter a password.</div>
</div>
<div class="mb-3">
<label for="add-role" class="form-label">Role *</label>
<select name="role" id="add-role" class="form-select" required>
<option value="member" selected>Member</option>
<option value="admin">Admin</option>
</select>
<div class="invalid-feedback">Please select a role.</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Add User</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div>
How to integrate this into your admin dashboard (from your first code)? There are two good approaches:
Option 1: Keep this as a separate user management page (recommended)
The dashboard’s Users sidebar link points here.
Your dashboard's "Users" section's link can point to this page, or you can get rid of the users table and add user modal from dashboard and just link to this full-featured page.
This keeps dashboard clean and specialized.
Update the dashboard sidebar Users menu link:
<a href="manage_users.php"><i class="bi bi-people"></i> Users</a>
This is the simplest and cleanest.
Option 2: Merge this code into the dashboard page If you want all in one page, then:
Move your entire user management PHP block (session, PDO, post handlers, fetch users) into the top of your dashboard PHP (before output).
Paste the Users Section HTML part (the table + add user modal) of this code inside your dashboard’s <main id="content"> where you have the Users section.
Also paste the JS for validation and datatable initialization inside the dashboard’s <script> section.
Change the POST handler in the dashboard accordingly (check for add_user and delete_user in the same way).
Remove or disable the existing users HTML block in the dashboard so they don't appear twice.
Provide feedback messages at top of content area by reading $_SESSION errors/successes.
Note: You’ll want to unify CSS styles and avoid duplicates like duplicate DataTables or bootstrap links.
Quick code snippet for redirecting sidebar Users link: <!-- In dashboard sidebar nav -->
<a href="manage_users.php"><i class="bi bi-people"></i> Users</a>
Summary
Your manage_users.php standalone page is complete, well-structured, and fully functional.
The easiest is to just link to this page from your dashboard sidebar.
Alternatively, you can merge post handlers, fetch queries, and user table/modal into the dashboard page if you want everything on one page, but that’s more complex.
If you want me to generate the full merged dashboard page with integrated user management , just let me know!
Got it! Below is your fully merged admin dashboard page including the user management section integrated properly with the add/delete user logic and feedback.
What I did:
Added user add/delete POST handlers.
Moved feedback message display into dashboard’s content area.
Merged the full users table + add user modal inside the dashboard page.
Ensured PDO is created once.
Used session flash messages for feedback.
Initialized DataTables for both users and recent borrows.
Updated sidebar "Users" link to # since users are now fully on dashboard.
Left your original dashboard stats, recent borrows, books section intact.
<?php
session_start();
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit;
}
require 'config.php';
try {
$pdo = new PDO("mysql:host=localhost;dbname=library_db;charset=utf8mb4", 'root', 'root', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
die('Database connection failed: ' . htmlspecialchars($e->getMessage()));
}
// Handle POST requests
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action']) && $_POST['action'] === 'add_user') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$role = $_POST['role'] ?? 'member';
if ($username === '' || $password === '' || !in_array($role, ['admin', 'member'], true)) {
$_SESSION['error'] = 'All fields are required and role must be valid.';
} else {
// Check if username exists
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetchColumn() > 0) {
$_SESSION['error'] = 'Username already exists.';
} else {
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, password_hash, role, created_at) VALUES (?, ?, ?, NOW())");
$stmt->execute([$username, $password_hash, $role]);
$_SESSION['success'] = "User '$username' added successfully.";
}
}
} elseif (isset($_POST['delete_user'])) {
$user_id = (int)$_POST['delete_user'];
if ($user_id === 1) {
$_SESSION['error'] = 'Cannot delete main admin user.';
} else {
$stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$_SESSION['success'] = 'User deleted successfully.';
}
}
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
// Fetch stats
$totalUsers = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$totalBooks = $pdo->query("SELECT COUNT(*) FROM books")->fetchColumn();
$totalBorrowed = $pdo->query("SELECT COUNT(*) FROM borrow_records WHERE return_date IS NULL")->fetchColumn();
$totalAdmins = $pdo->query("SELECT COUNT(*) FROM users WHERE role='admin'")->fetchColumn();
// Fetch recent borrow records
$recentBorrows = $pdo->query("
SELECT br.id, u.username, b.title, br.borrow_date, br.due_date, br.return_date, br.fine
FROM borrow_records br
JOIN users u ON br.user_id = u.id
JOIN books b ON br.book_id = b.id
ORDER BY br.borrow_date DESC LIMIT 5
")->fetchAll();
// Fetch users to display in users table (limit 50 recent)
$users = $pdo->query("SELECT id, username, role, created_at FROM users ORDER BY created_at DESC LIMIT 50")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<title>Advanced Admin Dashboard - Library LMS</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables CSS -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
/* ===== Reset & Globals ===== */
body {
background-color: #f3f6fd;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #344767;
margin: 0;
overflow-y: scroll;
}
a {
text-decoration: none;
}
/* ===== Sidebar Styles ===== */
#sidebar {
position: fixed;
top: 0; bottom: 0; left: 0;
width: 250px;
background-color: #1b1f38;
color: #fff;
display: flex;
flex-direction: column;
padding: 1.5rem 1rem;
box-shadow: 2px 0 12px rgba(27,31,56,0.6);
z-index: 1030;
}
#sidebar .sidebar-brand {
font-size: 1.8rem;
font-weight: 700;
padding-bottom: 1rem;
border-bottom: 1px solid #3a3f67;
margin-bottom: 1.5rem;
letter-spacing: 2px;
user-select: none;
}
#sidebar nav {
flex-grow: 1;
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.7rem 1rem;
color: #a6abc8;
border-radius: 8px;
margin-bottom: 0.8rem;
font-weight: 600;
font-size: 1rem;
transition: background-color 0.25s ease, color 0.25s ease;
user-select: none;
}
#sidebar nav a .bi {
margin-right: 1rem;
font-size: 1.3rem;
}
#sidebar nav a.active,
#sidebar nav a:hover {
background: #5865f2;
color: #fff;
}
/* ===== Main Content Area ===== */
#content {
margin-left: 250px;
padding: 2.5rem 3rem;
transition: margin-left 0.3s ease;
min-height: 100vh;
}
/* ===== Top Navbar ===== */
.top-navbar {
display: flex;
justify-content: flex-end;
align-items: center;
padding-bottom: 2rem;
gap: 1rem;
}
.top-navbar span {
font-weight: 600;
font-size: 1rem;
color: #344767;
}
/* ===== Cards ===== */
.stat-card {
position: relative;
background: linear-gradient(135deg, #6e8efb, #a777e3);
color: #fff;
border-radius: 20px;
padding: 2rem 2.5rem;
box-shadow: 0 12px 20px rgba(110,142,251,.4);
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: default;
}
.stat-card:hover {
transform: translateY(-10px);
box-shadow: 0 18px 30px rgba(110,142,251,.6);
}
.stat-icon {
position: absolute;
top: 30px;
right: 30px;
font-size: 4rem;
opacity: 0.12;
user-select: none;
}
.stat-title {
font-weight: 700;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.1em;
opacity: 0.8;
margin-bottom: 0.8rem;
user-select: none;
}
.stat-value {
font-size: 2.8rem;
font-weight: 800;
user-select: text;
}
/* ===== Tables ===== */
table {
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0,0,0,0.05);
overflow: hidden;
}
table thead {
background-color: #5865f2 !important;
color: white !important;
font-weight: 600 !important;
}
table thead th, table tbody td {
vertical-align: middle !important;
}
table tbody tr:hover {
background-color: #ecefff;
transition: background-color 0.25s ease;
}
/* Badges */
.badge-role-admin {
background-color: #ec4899 !important;
font-weight: 600;
padding: 0.3em 0.75em;
border-radius: 12px;
}
.badge-role-member {
background-color: #6b7280 !important;
font-weight: 600;
padding: 0.3em 0.75em;
border-radius: 12px;
}
/* Buttons with shadows and scale */
.btn {
transition: transform 0.2s ease, box-shadow 0.3s ease;
}
.btn:hover {
transform: translateY(-3px);
filter: brightness(110%);
box-shadow: 0 10px 25px rgb(99 102 241 / 0.45);
}
/* Modal */
.modal-content {
border-radius: 1rem;
}
.modal-header {
border-bottom: 1px solid #dee2e6;
}
.modal-footer {
border-top: 1px solid #dee2e6;
}
/* Alert messages */
.alert-dismissible .btn-close {
position: absolute;
top: 0.75rem;
right: 1rem;
}
</style>
</head>
<body>
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-brand">Library LMS</div>
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="#"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Content -->
<main id="content" class="container-fluid">
<div class="top-navbar mb-4">
<span>Welcome, <?=htmlspecialchars($_SESSION['username'])?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-sm">Logout <i class="bi bi-box-arrow-right"></i></a>
</div>
<!-- Feedback Messages -->
<?php if (isset($_SESSION['error'])): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?=htmlspecialchars($_SESSION['error'])?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['success'])): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?=htmlspecialchars($_SESSION['success'])?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['success']); ?>
<?php endif; ?>
<!-- Stats Cards -->
<div class="row g-4 mb-5">
<div class="col-md-3">
<div class="stat-card">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#4ade80,#16a34a);">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#facc15,#ca8a04);">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#ef4444,#b91c1c);">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</div>
</div>
</div>
<!-- Recent Borrow Records -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Recent Borrow Records</h3>
<div class="table-responsive shadow rounded">
<table id="recentBorrowsTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th><th>User</th><th>Book</th><th>Borrow Date</th><th>Due Date</th><th>Return Date</th><th>Fine</th>
</tr>
</thead>
<tbody>
<?php foreach($recentBorrows as $r): ?>
<tr>
<td><?= $r['id'] ?></td>
<td><?= htmlspecialchars($r['username']) ?></td>
<td><?= htmlspecialchars($r['title']) ?></td>
<td><?= $r['borrow_date'] ?></td>
<td><?= $r['due_date'] ?></td>
<td><?= $r['return_date'] ?? '-' ?></td>
<td><?= $r['fine'] ? '$'.number_format($r['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">View All Borrow Records</a>
</section>
<!-- Users Section -->
<section>
<h3 class="fw-semibold mb-4">Users</h3>
<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#addUserModal">
<i class="bi bi-person-plus-fill"></i> Add User
</button>
<div class="table-responsive shadow rounded" style="max-height: 400px; overflow-y: auto;">
<table id="usersTable" class="table table-hover align-middle">
<thead class="table-secondary">
<tr>
<th>ID</th><th>Username</th><th>Role</th><th>Created At</th><th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): ?>
<tr>
<td><?= (int)$u['id'] ?></td>
<td><?= htmlspecialchars($u['username']) ?></td>
<td>
<?php if ($u['role'] === 'admin'): ?>
<span class="badge badge-role-admin">Admin</span>
<?php else: ?>
<span class="badge badge-role-member">Member</span>
<?php endif; ?>
</td>
<td><?= htmlspecialchars($u['created_at']) ?></td>
<td>
<?php if ($u['id'] !== 1): ?>
<form method="post" class="d-inline" onsubmit="return confirm('Delete user <?=htmlspecialchars(addslashes($u['username']))?>?');">
<input type="hidden" name="delete_user" value="<?= (int)$u['id'] ?>" />
<button type="submit" class="btn btn-sm btn-danger" title="Delete User"><i class="bi bi-trash-fill"></i></button>
</form>
<?php else: ?>
<span class="text-muted fst-italic">Protected</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</section>
<hr class="my-5"/>
<!-- Books Section Summary -->
<section>
<h3 class="fw-semibold">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg">
<i class="bi bi-book-fill"></i> Manage Books
</a>
</section>
</main>
<!-- Add User Modal -->
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="addUserModalLabel" aria-hidden="true" style="--bs-modal-width: 400px;">
<div class="modal-dialog">
<form method="post" class="modal-content needs-validation" novalidate>
<input type="hidden" name="action" value="add_user" />
<div class="modal-header">
<h5 class="modal-title" id="addUserModalLabel">Add New User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" ></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="add-username" class="form-label fw-semibold">Username *</label>
<input type="text" name="username" id="add-username" class="form-control" placeholder="Enter username" required />
<div class="invalid-feedback">Please enter a username.</div>
</div>
<div class="mb-3">
<label for="add-password" class="form-label fw-semibold">Password *</label>
<input type="password" name="password" id="add-password" class="form-control" placeholder="Enter password" required />
<div class="invalid-feedback">Please enter a password.</div>
</div>
<div class="mb-3">
<label for="add-role" class="form-label fw-semibold">Role *</label>
<select name="role" id="add-role" class="form-select" required>
<option value="member" selected>Member</option>
<option value="admin">Admin</option>
</select>
<div class="invalid-feedback">Please select a role.</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary fw-semibold">Add User</button>
<button type="button" class="btn btn-light fw-semibold" data-bs-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
<!-- Bootstrap JS and Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Initialize Simple-DataTables
new simpleDatatables.DataTable("#usersTable");
new simpleDatatables.DataTable("#recentBorrowsTable");
// Bootstrap form validation
const forms = document.querySelectorAll('.needs-validation');
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
});
});
// Auto open 'Add User' modal if error occurred adding user
<?php if (isset($_SESSION['error']) && isset($_POST['action']) && $_POST['action'] === 'add_user'): ?>
var addUserModal = new bootstrap.Modal(document.getElementById('addUserModal'));
addUserModal.show();
<?php endif; ?>
});
</script>
</body>
</html>
Notes:
Password hash column name : I used password_hash for the DB insert to match your new code (make sure your DB column matches this name).
Feedback via $_SESSION['error'] and $_SESSION['success'] and automatic redirect after POST implemented.
Confirm JavaScript to auto-show modal after validation error works only if you try to add user with error.
The sidebar Users link points to # because the user management is fully inside this dashboard page now.
Keep your logout logic from your original dashboard (like ?action=logout in URL) working, you can add it in PHP above if you wish.
If you want me to also add logout handler in this same page or anything else, just ask!
users.php
The admin dashboard page (the one you initially showed) where users were partially shown.
How do you want to integrate both?
1. Keep users.php as a separate full user management page, and**
In your dashboard sidebar, make the Users link point to users.php
Remove or simplify the user section on the dashboard (e.g., just a summary card or basic info)
This keeps the dashboard cleaner and delegates full user management to users.php
<!-- Sidebar -->
<a href="users.php"><i class="bi bi-people"></i> Users</a>
2. Embed the users.php functionality fully inside your dashboard page
Move POST handlers, queries, and UI from users.php into dashboard page PHP and HTML
Possibly keep users.php only if you want a standalone page, or redirect from it elsewhere (or deprecate it)
3. Redirect users.php to dashboard or dashboard to users.php
Decide one canonical user management page and redirect other to it.
So, concrete recommendation:
Since you already have a full users.php, link from dashboard sidebar Users menu to users.php
Remove the inline user management section (table + add user modal) from dashboard or replace it with a simple card with a link to users.php page.
Example sidebar modification to link out: In your dashboard, under sidebar:
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a> <!-- <-- here -->
</nav>
Example small users summary block on dashboard instead of big user table/modal: <section>
<h3 class="fw-semibold mb-4">Users</h3>
<p>Total users: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary">
<i class="bi bi-people"></i> Manage Users
</a>
</section>
This way dashboard keeps stats and a simple link, all detailed user management goes to your users.php.
If you want me to generate updated dashboard code with this arrangement, just ask! Or if you want me to guide you how to merge users.php into dashboard page (Option 2), just let me know! Great! For Option 1 , you want to keep your existing users.php as a separate user management page and from your dashboard sidebar menu's Users link, you want to point to users.php.
Here’s exactly what you need to do:
1. Update your dashboard sidebar navigation Users link
In your dashboard page, find this part:
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="#"><i class="bi bi-people"></i> Users</a> <!-- Change this -->
</nav>
Change it to:
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a> <!-- Point to your users.php -->
</nav>
2. Optionally remove the full Users section in the Dashboard page
Since you have a full user management page (users.php), you can remove the entire users table and "Add User" modal section from your dashboard page or replace it with a simple summary and button linking to users.php.
Replace the big users block in the dashboard with this small block for info/link:
<section>
<h3 class="fw-semibold mb-4">Users</h3>
<p>Total users: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary">
<i class="bi bi-people"></i> Manage Users
</a>
</section>
This keeps dashboard lightweight and focused on stats and summaries, while pushing user management to a dedicated page.
3. Make sure your users.php has session check, database connection, and user add/delete logic as you posted.
And, optionally, add a navigation menu in users.php to go back to dashboard:
<nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow-sm mb-4">
<div class="container">
<a class="navbar-brand" href="admin_dashboard.php">Library LMS Admin</a>
<div>
<a href="admin_dashboard.php" class="btn btn-outline-light btn-sm me-2">
<i class="bi bi-arrow-left"></i> Dashboard
</a>
<a href="?action=logout" class="btn btn-outline-light btn-sm">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</div>
</div>
</nav>
Summary
The Users menu item in the sidebar redirect to users.php.
Dashboard shows just a summary and link to full user management page.
users.php remains your full-featured user management.
If you want, I can help you update your dashboard page to remove the old users section and add the simple block as shown, just ask!
Absolutely! Below is a clean , modern , and fully functional admin_dashboard.php based on your requirements, best practices, and your existing code. It includes:
Secure session check and logout handling
PDO connection with error handling
Dashboard cards for quick stats (users, books, borrowed books, admins)
Recent borrow records (last 5)
A Users summary block with a button linking to your fully-featured users.php
A Books inventory summary with a link to the books page
Responsive and clean Bootstrap 5 styling + Simple DataTables
Proper escaping and validation
Feedback area for messages (you can add flash messages later if needed)
Usage:
Place it in your admin area (e.g. admin_dashboard.php)
Make sure you have users.php (for full user management), books.php, and borrow_records.php
Sidebar navigation links point to the right pages
?action=logout will log the user out
<?php
session_start();
// Logout handler
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
session_destroy();
header('Location: login.php');
exit;
}
// Check if user is logged in and is admin
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit;
}
require 'config.php';
try {
$pdo = new PDO("mysql:host=localhost;dbname=library_db;charset=utf8mb4", 'root', 'root', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
die('Database connection failed: ' . htmlspecialchars($e->getMessage()));
}
// Fetch stats from database
$totalUsers = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$totalBooks = $pdo->query("SELECT COUNT(*) FROM books")->fetchColumn();
$totalBorrowed = $pdo->query("SELECT COUNT(*) FROM borrow_records WHERE return_date IS NULL")->fetchColumn();
$totalAdmins = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'admin'")->fetchColumn();
// Fetch recent borrow records (limit 5)
$recentBorrows = $pdo->query("
SELECT br.id, u.username, b.title, br.borrow_date, br.due_date, br.return_date, br.fine
FROM borrow_records br
JOIN users u ON br.user_id = u.id
JOIN books b ON br.book_id = b.id
ORDER BY br.borrow_date DESC
LIMIT 5
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Admin Dashboard - Library LMS</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
body {
background-color: #f3f6fd;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #344767;
margin: 0;
overflow-y: scroll;
}
a {
text-decoration: none;
}
#sidebar {
position: fixed;
top: 0; bottom: 0; left: 0;
width: 250px;
background-color: #1b1f38;
color: #fff;
display: flex;
flex-direction: column;
padding: 1.5rem 1rem;
box-shadow: 2px 0 12px rgba(27,31,56,0.6);
z-index: 1030;
}
#sidebar .sidebar-brand {
font-size: 1.8rem;
font-weight: 700;
padding-bottom: 1rem;
border-bottom: 1px solid #3a3f67;
margin-bottom: 1.5rem;
letter-spacing: 2px;
user-select: none;
}
#sidebar nav {
flex-grow: 1;
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.7rem 1rem;
color: #a6abc8;
border-radius: 8px;
margin-bottom: 0.8rem;
font-weight: 600;
font-size: 1rem;
transition: background-color 0.25s ease, color 0.25s ease;
user-select: none;
}
#sidebar nav a .bi {
margin-right: 1rem;
font-size: 1.3rem;
}
#sidebar nav a.active,
#sidebar nav a:hover {
background: #5865f2;
color: #fff;
}
#content {
margin-left: 250px;
padding: 2.5rem 3rem;
min-height: 100vh;
}
.top-navbar {
display: flex;
justify-content: flex-end;
align-items: center;
padding-bottom: 2rem;
gap: 1rem;
}
.top-navbar span {
font-weight: 600;
font-size: 1rem;
color: #344767;
}
.stat-card {
position: relative;
background: linear-gradient(135deg, #6e8efb, #a777e3);
color: #fff;
border-radius: 20px;
padding: 2rem 2.5rem;
box-shadow: 0 12px 20px rgba(110,142,251,.4);
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: default;
}
.stat-card:hover {
transform: translateY(-10px);
box-shadow: 0 18px 30px rgba(110,142,251,.6);
}
.stat-icon {
position: absolute;
top: 30px;
right: 30px;
font-size: 4rem;
opacity: 0.12;
user-select: none;
}
.stat-title {
font-weight: 700;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.1em;
opacity: 0.8;
margin-bottom: 0.8rem;
user-select: none;
}
.stat-value {
font-size: 2.8rem;
font-weight: 800;
user-select: text;
}
table {
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0,0,0,0.05);
overflow: hidden;
}
table thead {
background-color: #5865f2 !important;
color: white !important;
font-weight: 600 !important;
}
table thead th, table tbody td {
vertical-align: middle !important;
}
table tbody tr:hover {
background-color: #ecefff;
transition: background-color 0.25s ease;
}
.btn-primary:hover {
filter: brightness(110%);
box-shadow: 0 10px 25px rgba(99,102,241,0.45);
transform: translateY(-3px);
}
</style>
</head>
<body>
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-brand">Library LMS</div>
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Main Content -->
<main id="content" class="container-fluid">
<div class="top-navbar mb-4">
<span>Welcome, <?= htmlspecialchars($_SESSION['username']) ?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-sm">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</div>
<!-- Stats Cards -->
<div class="row g-4 mb-5">
<div class="col-md-3">
<div class="stat-card">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#4ade80,#16a34a);">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#facc15,#ca8a04);">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#ef4444,#b91c1c);">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</div>
</div>
</div>
<!-- Recent Borrow Records Table -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Recent Borrow Records</h3>
<div class="table-responsive shadow rounded">
<table id="recentBorrowsTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th><th>User</th><th>Book</th><th>Borrow Date</th><th>Due Date</th><th>Return Date</th><th>Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBorrows as $borrow): ?>
<tr>
<td><?= (int)$borrow['id'] ?></td>
<td><?= htmlspecialchars($borrow['username']) ?></td>
<td><?= htmlspecialchars($borrow['title']) ?></td>
<td><?= htmlspecialchars($borrow['borrow_date']) ?></td>
<td><?= htmlspecialchars($borrow['due_date']) ?></td>
<td><?= $borrow['return_date'] ? htmlspecialchars($borrow['return_date']) : '-' ?></td>
<td><?= $borrow['fine'] !== null && $borrow['fine'] > 0 ? '$' . number_format($borrow['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">View All Borrow Records</a>
</section>
<!-- Users Summary -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Users</h3>
<p>Total users registered: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary">
<i class="bi bi-people"></i> Manage Users
</a>
</section>
<!-- Books Summary -->
<section>
<h3 class="fw-semibold mb-3">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg">
<i class="bi bi-book-fill"></i> Manage Books
</a>
</section>
</main>
<!-- Bootstrap JS and Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Initialize DataTables for recent borrow records table
new simpleDatatables.DataTable("#recentBorrowsTable");
});
</script>
</body>
</html>
Explanation
Sidebar navigation with proper active link and links to all pages (users.php separately)
Responsive cards with hover effects and icons for summary statistics
Recent borrow records displayed with a styled DataTable for sortable/searchable table
Simple Users summary with a Manage Users button which directs to your comprehensive users.php
Clean Books summary section with a Manage Books button
Consistent, modern UI with Bootstrap 5 and Bootstrap Icons
Secure session checks, PDO with error mode and prepared statements (queries safe)
Logout link works via URL param ?action=logout
If you want me to help build or adjust your users.php or other pages to integrate seamlessly with this, feel free to ask!
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
body {
background-color: #f3f6fd;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #344767;
margin: 0;
overflow-y: scroll;
}
a {
text-decoration: none;
}
#sidebar {
position: fixed;
top: 0; bottom: 0; left: 0;
width: 250px;
background-color: #1b1f38;
color: #fff;
display: flex;
flex-direction: column;
padding: 1.5rem 1rem;
box-shadow: 2px 0 12px rgba(27,31,56,0.6);
z-index: 1030;
}
#sidebar .sidebar-brand {
font-size: 1.8rem;
font-weight: 700;
padding-bottom: 1rem;
border-bottom: 1px solid #3a3f67;
margin-bottom: 1.5rem;
letter-spacing: 2px;
user-select: none;
}
#sidebar nav {
flex-grow: 1;
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.7rem 1rem;
color: #a6abc8;
border-radius: 8px;
margin-bottom: 0.8rem;
font-weight: 600;
font-size: 1rem;
transition: background-color 0.25s ease, color 0.25s ease;
user-select: none;
}
#sidebar nav a .bi {
margin-right: 1rem;
font-size: 1.3rem;
}
#sidebar nav a.active,
#sidebar nav a:hover {
background: #5865f2;
color: #fff;
}
#content {
margin-left: 250px;
padding: 2.5rem 3rem;
min-height: 100vh;
}
.top-navbar {
display: flex;
justify-content: flex-end;
align-items: center;
padding-bottom: 2rem;
gap: 1rem;
}
.top-navbar span {
font-weight: 600;
font-size: 1rem;
color: #344767;
}
.stat-card {
position: relative;
background: linear-gradient(135deg, #6e8efb, #a777e3);
color: #fff;
border-radius: 20px;
padding: 2rem 2.5rem;
box-shadow: 0 12px 20px rgba(110,142,251,.4);
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: default;
}
.stat-card:hover {
transform: translateY(-10px);
box-shadow: 0 18px 30px rgba(110,142,251,.6);
}
.stat-icon {
position: absolute;
top: 30px;
right: 30px;
font-size: 4rem;
opacity: 0.12;
user-select: none;
}
.stat-title {
font-weight: 700;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.1em;
opacity: 0.8;
margin-bottom: 0.8rem;
user-select: none;
}
.stat-value {
font-size: 2.8rem;
font-weight: 800;
user-select: text;
}
table {
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0,0,0,0.05);
overflow: hidden;
}
table thead {
background-color: #5865f2 !important;
color: white !important;
font-weight: 600 !important;
}
table thead th, table tbody td {
vertical-align: middle !important;
}
table tbody tr:hover {
background-color: #ecefff;
transition: background-color 0.25s ease;
}
.btn-primary:hover {
filter: brightness(110%);
box-shadow: 0 10px 25px rgba(99,102,241,0.45);
transform: translateY(-3px);
}
</style>
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-brand">Library LMS</div>
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Main Content -->
<main id="content" class="container-fluid">
<div class="top-navbar mb-4">
<span>Welcome, <?= htmlspecialchars($_SESSION['username']) ?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-sm">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</div>
<!-- Stats Cards -->
<div class="row g-4 mb-5">
<div class="col-md-3">
<div class="stat-card">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#4ade80,#16a34a);">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#facc15,#ca8a04);">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#ef4444,#b91c1c);">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</div>
</div>
</div>
<!-- Recent Borrow Records Table -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Recent Borrow Records</h3>
<div class="table-responsive shadow rounded">
<table id="recentBorrowsTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th><th>User</th><th>Book</th><th>Borrow Date</th><th>Due Date</th><th>Return Date</th><th>Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBorrows as $borrow): ?>
<tr>
<td><?= (int)$borrow['id'] ?></td>
<td><?= htmlspecialchars($borrow['username']) ?></td>
<td><?= htmlspecialchars($borrow['title']) ?></td>
<td><?= htmlspecialchars($borrow['borrow_date']) ?></td>
<td><?= htmlspecialchars($borrow['due_date']) ?></td>
<td><?= $borrow['return_date'] ? htmlspecialchars($borrow['return_date']) : '-' ?></td>
<td><?= $borrow['fine'] !== null && $borrow['fine'] > 0 ? '$' . number_format($borrow['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">View All Borrow Records</a>
</section>
<!-- Users Summary -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Users</h3>
<p>Total users registered: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary">
<i class="bi bi-people"></i> Manage Users
</a>
</section>
<!-- Books Summary -->
<section>
<h3 class="fw-semibold mb-3">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg">
<i class="bi bi-book-fill"></i> Manage Books
</a>
</section>
</main>
<!-- Bootstrap JS and Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Initialize DataTables for recent borrow records table
new simpleDatatables.DataTable("#recentBorrowsTable");
});
</script>
Understood! You want a more modern, polished, and advanced-looking Admin Dashboard UI that feels professional, clean, with better spacing, typography, colors, icons, and subtle animations — while keeping the current content and functionality.
Below is a full updated code with:
A sleek sidebar with collapsible submenu support (expandable if you want in future)
A top navbar with user avatar placeholder and logout dropdown (modern style)
Cards with subtle shadows, neat layout, and consistent colors
Tables with improved styling and hover effects
Cleaner typography & spacing using Bootstrap 5 utilities + custom CSS
Responsive improvements and mobile-friendly sidebar toggle
Additional icons & color accents for better UX
Smooth transitions and hover effects for interactivity
Dashboard focused only on admin role as your logic expects
What I improved?
Sidebar is sticky with collapsible menu (you can expand this later)
Top navbar has user avatar dropdown with logout option
Cards have different color themes, consistent, with nice icons
Tables styled with soft shadows and hover highlights
Responsive sidebar toggle on smaller devices
Consistent spacing and font sizes with improved readability
Light shadow and border radius for card containers and tables
Clear Calls-to-action buttons with icons
Overall clean, minimal, professional look
Full updated admin_dashboard.php code:
<?php
session_start();
// Logout handler
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
session_destroy();
header('Location: login.php');
exit;
}
// Check admin authentication
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit;
}
require 'config.php';
try {
$pdo = new PDO("mysql:host=localhost;dbname=library_db;charset=utf8mb4", 'root', 'root', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
die('Database connection failed: ' . htmlspecialchars($e->getMessage()));
}
// Fetch dashboard stats
$totalUsers = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$totalBooks = $pdo->query("SELECT COUNT(*) FROM books")->fetchColumn();
$totalBorrowed = $pdo->query("SELECT COUNT(*) FROM borrow_records WHERE return_date IS NULL")->fetchColumn();
$totalAdmins = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'admin'")->fetchColumn();
// Fetch recent borrows, limit 5
$recentBorrows = $pdo->query("
SELECT br.id, u.username, b.title, br.borrow_date, br.due_date, br.return_date, br.fine
FROM borrow_records br
JOIN users u ON br.user_id = u.id
JOIN books b ON br.book_id = b.id
ORDER BY br.borrow_date DESC
LIMIT 5
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Admin Dashboard - Library LMS</title>
<!-- Bootstrap v5.3 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables CSS -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
/* Reset & base */
body {
min-height: 100vh;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #f7f9fc;
color: #323a50;
}
/* Sidebar styles */
#sidebar {
position: fixed;
top: 0; bottom: 0; left: 0;
width: 260px;
background: linear-gradient(180deg, #5048e5 0%, #3f3eb8 100%);
color: #e0e0e0;
box-shadow: 0 10px 25px rgb(79 70 229 / 0.2);
transition: all 0.3s ease;
z-index: 1040;
display: flex;
flex-direction: column;
}
#sidebar .sidebar-brand {
font-size: 1.8rem;
font-weight: 700;
padding: 2rem 1.5rem;
letter-spacing: 3px;
user-select: none;
color: #fff;
border-bottom: 1px solid rgba(255,255,255,0.12);
text-align: center;
text-shadow: 1px 1px 3px rgba(0,0,0,0.15);
}
#sidebar nav {
margin-top: 1rem;
flex-grow: 1;
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.85rem 1.8rem;
color: #d1d5db;
font-weight: 600;
font-size: 1.1rem;
border-left: 4px solid transparent;
transition: all 0.3s ease;
user-select: none;
gap: 1rem;
cursor: pointer;
}
#sidebar nav a:hover,
#sidebar nav a.active {
background: rgba(255 255 255 / 0.15);
color: white;
border-left-color: #fff;
}
#sidebar nav a .bi {
font-size: 1.5rem;
}
/* Content wrapper */
#content {
margin-left: 260px;
padding: 2.5rem 3rem;
min-height: 100vh;
transition: margin-left 0.3s ease;
}
/* Top navbar */
.top-navbar {
display: flex;
justify-content: flex-end;
align-items: center;
gap: 1.5rem;
padding-bottom: 2rem;
}
.top-navbar span {
font-weight: 600;
font-size: 1.1rem;
color: #323a50;
user-select: none;
}
/* --- Cards --- */
.stat-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
gap: 1.8rem;
margin-bottom: 3.5rem;
}
.stat-card {
position: relative;
background: #fff;
border-radius: 16px;
padding: 2.2rem 2.3rem 2.3rem 2.3rem;
color: #3a416f;
box-shadow:
0 1.8px 3.6px rgb(0 0 0 / 0.04),
0 4.3px 8.5px rgb(0 0 0 / 0.06),
0 12px 24px rgb(0 0 0 / 0.12);
transition: box-shadow 0.3s ease, transform 0.3s ease;
cursor: default;
}
.stat-card:hover {
box-shadow:
0 6px 20px rgb(79 70 229 / 0.2),
0 12px 35px rgb(79 70 229 / 0.25);
transform: translateY(-10px);
}
.stat-icon {
position: absolute;
top: 20px;
right: 25px;
font-size: 3.5rem;
opacity: 0.08;
user-select: none;
color: #6d6df7;
}
.stat-title {
font-weight: 700;
font-size: 0.9rem;
color: #718096;
text-transform: uppercase;
letter-spacing: 0.09em;
margin-bottom: 0.6rem;
user-select: none;
}
.stat-value {
font-size: 3.5rem;
font-weight: 900;
user-select: text;
color: #3a416f;
}
/* Individual card colors */
.stat-card.users {
color: #2563eb;
}
.stat-card.users .stat-icon {
color: #2563eb;
}
.stat-card.books {
color: #16a34a;
}
.stat-card.books .stat-icon {
color: #16a34a;
}
.stat-card.borrowed {
color: #d97706;
}
.stat-card.borrowed .stat-icon {
color: #d97706;
}
.stat-card.admins {
color: #dc2626;
}
.stat-card.admins .stat-icon {
color: #dc2626;
}
/* Tables */
.table-container {
background: white;
border-radius: 14px;
padding: 1.5rem 2rem;
box-shadow:
0 4px 18px rgb(0 0 0 / 0.1);
margin-bottom: 3rem;
overflow-x: auto;
}
table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
table-layout: fixed;
}
thead th {
background: #5048e5;
color: white;
font-weight: 700;
font-size: 1rem;
padding: 1rem 1.3rem;
text-align: left;
user-select: none;
border-right: 1px solid rgba(255,255,255,0.15);
}
thead th:last-child {
border-right: none;
}
tbody tr:hover {
background: #f6f8ff;
cursor: default;
}
tbody td {
padding: 0.9rem 1.3rem;
vertical-align: middle;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-weight: 600;
font-size: 0.95rem;
color: #4a5168;
border-bottom: 1px solid #e7eaf3;
}
tbody td.actions {
text-align: center;
white-space: nowrap;
}
/* Badges */
.badge-admin {
background-color: #ef4444;
font-weight: 700;
font-size: 0.85rem;
color: white;
padding: 0.35em 0.75em;
border-radius: 12px;
user-select: none;
}
.badge-member {
background-color: #6b7280;
font-weight: 700;
font-size: 0.85rem;
color: white;
padding: 0.35em 0.75em;
border-radius: 12px;
user-select: none;
}
/* Buttons */
.btn-primary {
background-color: #5048e5;
border: none;
font-weight: 600;
font-size: 1rem;
padding: 0.55rem 1.4rem;
border-radius: 12px;
box-shadow:
0 3px 10px rgb(79 70 229 / 0.3);
transition: all 0.3s ease;
}
.btn-primary:hover, .btn-primary:focus {
background-color: #3f3eb8;
box-shadow:
0 6px 20px rgb(79 70 229 / 0.42);
transform: translateY(-3px);
}
/* Responsive tweaks */
@media (max-width: 991px) {
#sidebar {
width: 220px;
}
#content {
margin-left: 220px;
padding: 2rem;
}
}
@media (max-width: 768px) {
#sidebar {
position: static;
width: 100%;
height: auto;
padding: 1rem 1rem;
flex-direction: row;
align-items: center;
overflow-x: auto;
}
#sidebar .sidebar-brand {
flex: 1 0 auto;
margin-bottom: 0;
padding: 0 0.5rem 0 1rem;
font-size: 1.3rem;
}
#sidebar nav {
flex-direction: row;
margin-top: 0;
flex: 3 1 auto;
}
#sidebar nav a {
margin-bottom: 0;
padding: 0.6rem 0.85rem;
font-size: 0.95rem;
}
#content {
margin-left: 0;
padding: 1.5rem 1.5rem 3rem;
}
.stat-row {
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 1.3rem;
}
}
</style>
</head>
<body>
<!-- Sidebar -->
<nav id="sidebar" aria-label="Sidebar Navigation">
<div class="sidebar-brand">
Library LMS
</div>
<nav>
<a href="#" class="active" aria-current="page"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Main Content -->
<main id="content" role="main" tabindex="-1" class="container-fluid">
<!-- Top Navbar -->
<div class="top-navbar">
<span>Welcome, <?=htmlspecialchars($_SESSION['username'])?></span>
<div class="dropdown">
<button class="btn btn-outline-primary btn-sm dropdown-toggle d-flex align-items-center gap-2" type="button" id="userMenuButton" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">
<i class="bi bi-person-circle fs-5"></i> Account
</button>
<ul class="dropdown-menu dropdown-menu-end shadow" aria-labelledby="userMenuButton">
<li><a class="dropdown-item" href="?action=logout"><i class="bi bi-box-arrow-right me-2"></i> Logout</a></li>
</ul>
</div>
</div>
<!-- Statistics Cards -->
<section class="stat-row" aria-label="Dashboard statistics summary">
<article class="stat-card users" tabindex="0" aria-label="Total users count">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</article>
<article class="stat-card books" tabindex="0" aria-label="Total books count">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</article>
<article class="stat-card borrowed" tabindex="0" aria-label="Borrowed books count">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</article>
<article class="stat-card admins" tabindex="0" aria-label="Total admin users count">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</article>
</section>
<!-- Recent Borrow Records -->
<section aria-labelledby="recent-borrows-heading" class="mb-5">
<h3 id="recent-borrows-heading" class="fw-semibold mb-4 display-6">Recent Borrow Records</h3>
<div class="table-container shadow rounded">
<table id="recentBorrowsTable" class="table table-striped align-middle" aria-describedby="recent-borrows-desc">
<caption id="recent-borrows-desc" class="visually-hidden">Table showing 5 latest borrow records with user, book, dates and fines.</caption>
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">User</th>
<th scope="col">Book</th>
<th scope="col">Borrow Date</th>
<th scope="col">Due Date</th>
<th scope="col">Return Date</th>
<th scope="col">Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBorrows as $b): ?>
<tr>
<td><?= (int)$b['id'] ?></td>
<td><?= htmlspecialchars($b['username']) ?></td>
<td><?= htmlspecialchars($b['title']) ?></td>
<td><?= htmlspecialchars($b['borrow_date']) ?></td>
<td><?= htmlspecialchars($b['due_date']) ?></td>
<td><?= $b['return_date'] ? htmlspecialchars($b['return_date']) : '-' ?></td>
<td><?= $b['fine'] && $b['fine'] > 0 ? '$' . number_format($b['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">
View All Borrow Records <i class="bi bi-arrow-right"></i>
</a>
</section>
<!-- Users Summary -->
<section aria-labelledby="users-summary-heading" class="mb-5">
<h3 id="users-summary-heading" class="fw-semibold mb-4 display-6">Users</h3>
<p class="fs-5">Total users registered: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary d-inline-flex align-items-center gap-2">
<i class="bi bi-people-fill fs-5"></i> Manage Users
</a>
</section>
<!-- Books Summary -->
<section aria-labelledby="books-summary-heading" class="mb-5">
<h3 id="books-summary-heading" class="fw-semibold mb-3 display-6">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg d-inline-flex align-items-center gap-2">
<i class="bi bi-book-fill fs-4"></i> Manage Books
</a>
</section>
</main>
<!-- Bootstrap JS bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
new simpleDatatables.DataTable("#recentBorrowsTable", {
searchable: true,
fixedHeight: true,
perPage: 5
});
});
</script>
</body>
</html>
Visual highlights:
Sidebar with beautiful purple-blue gradient and clear active highlight
Top Navbar with user icon and dropdown (ready for adding profile, settings later)
Dashboard cards have distinct colors for Users, Books, Borrowed Books, Admins
Tables with striped rows, smooth hover highlight, and caption for accessibility
Buttons with icons, nice spacing, subtle hover animations
Responsive layout: sidebar compresses on smaller devices to keep content accessible
Typography uses various Bootstrap sizing classes (display-6, fs-5, etc) for clear hierarchy
If you want to customize further:
You can add user avatar images and profile links in the top navbar
You can add a collapsible sidebar toggle button for mobile view
Add dark mode toggle easily with CSS variables or Bootstrap 5 utilities
Expand dashboard stats with charts (Chart.js integration is common)
Performance: paginate tables on server side if large data
How does this work?
Save as admin_dashboard.php
Use your existing users.php, books.php, borrow_records.php pages linked from sidebar/buttons
Make sure Bootstrap 5, Bootstrap Icons & Simple DataTables CDN scripts load fine
Feel free to ask me for:
Dark mode styling
Bootstrap 5 navbar/sidebar toggles vs fixed sidebar
Chart.js charts integration for stats
Or merging add/delete user modals into dashboard
Hope this gets your admin dashboard looking sleek, professional, and modern! 🎉
ALTER TABLE users CHANGE password password_hash VARCHAR(255) NOT NULL;
This renames password column to password_hash.
Option 2: Update your PHP code to match your actual column
If your column name is password, just update your INSERT and queries accordingly, e.g.:
// Change this line in users.php where you insert user:
$stmt = $pdo->prepare("INSERT INTO users (username, password, role, created_at) VALUES (?, ?, ?, NOW())");
$stmt->execute([$username, $password_hash, $role]);
Summary
Find out your real password column name by checking your users table schema.
Use that exact column name in all your SQL queries.
Most LMS systems just use password for the hashed password.
Quick check In your SQL client or phpMyAdmin, run:
Look for the password column name.
Example change in your users.php from your original snippet $stmt = $pdo->prepare("INSERT INTO users (username, password_hash, role, created_at) VALUES (?, ?, ?, NOW())");
$stmt = $pdo->prepare("INSERT INTO users (username, password, role, created_at) VALUES (?, ?, ?, NOW())");
If you still want me to generate your fixed users.php code for best practices with that column fixed (and other improvements), let me know!
<!-- Display Feedback -->
<?php if (isset($_SESSION['error'])): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?=htmlspecialchars($_SESSION['error'])?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['success'])): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?=htmlspecialchars($_SESSION['success'])?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php unset($_SESSION['success']); ?>
<?php endif; ?>
<!-- Add User Button -->
<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#addUserModal">
<i class="bi bi-person-plus-fill"></i> Add User
</button>
<!-- Users Table -->
<div class="table-responsive shadow rounded">
<table id="usersTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Username</th>
<th>Role</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= (int)$user['id'] ?></td>
<td><?= htmlspecialchars($user['username']) ?></td>
<td>
<?php if ($user['role'] === 'admin'): ?>
<span class="badge badge-admin">Admin</span>
<?php else: ?>
<span class="badge badge-member">Member</span>
<?php endif; ?>
</td>
<td><?= htmlspecialchars($user['created_at']) ?></td>
<td>
<?php if ($user['id'] !== 1): ?>
<form method="post" class="d-inline" onsubmit="return confirm('Are you sure you want to delete user <?=htmlspecialchars(addslashes($user['username']))?>?');">
<input type="hidden" name="delete_user" value="<?= (int)$user['id'] ?>" />
<button type="submit" class="btn btn-sm btn-danger" title="Delete User"><i class="bi bi-trash-fill"></i></button>
</form>
<?php else: ?>
<span class="text-muted">Protected</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- Add User Modal -->
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="addUserModalLabel" aria-hidden="true" style="--bs-modal-width:400px;">
<div class="modal-dialog">
<form method="post" class="modal-content needs-validation" novalidate>
<input type="hidden" name="action" value="add_user" />
<div class="modal-header">
<h5 class="modal-title" id="addUserModalLabel">Add New User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="add-username" class="form-label">Username *</label>
<input type="text" name="username" id="add-username" class="form-control" required />
<div class="invalid-feedback">Please enter a username.</div>
</div>
<div class="mb-3">
<label for="add-password" class="form-label">Password *</label>
<input type="password" name="password" id="add-password" class="form-control" required />
<div class="invalid-feedback">Please enter a password.</div>
</div>
<div class="mb-3">
<label for="add-role" class="form-label">Role *</label>
<select name="role" id="add-role" class="form-select" required>
<option value="member" selected>Member</option>
<option value="admin">Admin</option>
</select>
<div class="invalid-feedback">Please select a role.</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Add User</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div>
The error you got originally was because in your INSERT statement you tried to insert into a non-existent column password_hash. In most schemas, the column's name usually is password.
How to fix:
Change all occurrences of password_hash in your SQL queries to password (or your actual password column name).
Here's your updated full code for users.php, with that fix applied and some minor best practice improvements:
<?php
session_start();
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit;
}
require 'config.php';
try {
$pdo = new PDO("mysql:host=localhost;dbname=library_db;charset=utf8mb4", 'root', 'root', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
die('Database connection failed: ' . htmlspecialchars($e->getMessage()));
}
// Handle POST requests
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action'])) {
if ($_POST['action'] === 'add_user') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$role = $_POST['role'] ?? 'member';
if ($username === '' || $password === '' || !in_array($role, ['admin', 'member'], true)) {
$_SESSION['error'] = 'All fields are required and role must be valid.';
} else {
// Check if username exists already
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetchColumn() > 0) {
$_SESSION['error'] = 'Username already exists.';
} else {
$password_hash = password_hash($password, PASSWORD_DEFAULT);
// Changed password_hash column to password to match DB column name
$stmt = $pdo->prepare("INSERT INTO users (username, password, role, created_at) VALUES (?, ?, ?, NOW())");
$stmt->execute([$username, $password_hash, $role]);
$_SESSION['success'] = "User '$username' added successfully.";
}
}
}
} elseif (isset($_POST['delete_user'])) {
$user_id = (int)$_POST['delete_user'];
if ($user_id === 1) {
$_SESSION['error'] = 'Cannot delete main admin user.';
} else {
$stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$_SESSION['success'] = 'User deleted successfully.';
}
}
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
// Fetch all users for display
$users = $pdo->query("SELECT id, username, role, created_at FROM users ORDER BY created_at DESC")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Manage Users - Library LMS</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables CSS -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
body {
background-color: #f0f2f5;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.badge-admin {
background-color: #dc3545 !important;
font-weight: 600;
font-size: 0.85rem;
color: #fff;
padding: 0.3em 0.75em;
border-radius: 12px;
}
.badge-member {
background-color: #6c757d !important;
font-weight: 600;
font-size: 0.85rem;
color: #fff;
padding: 0.3em 0.75em;
border-radius: 12px;
}
table.dataTable thead th {
background-color: #0d6efd !important;
color: white !important;
border-bottom: none !important;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow-sm mb-4">
<div class="container">
<a class="navbar-brand" href="admin_dashboard.php">Library LMS Admin</a>
<div>
<a href="admin_dashboard.php" class="btn btn-outline-light btn-sm me-2">
<i class="bi bi-arrow-left"></i> Dashboard
</a>
<a href="?action=logout" class="btn btn-outline-light btn-sm">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</div>
</div>
</nav>
<div class="container">
<h1 class="mb-4">Manage Users</h1>
<!-- Display Feedback Messages -->
<?php if (isset($_SESSION['error'])): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= htmlspecialchars($_SESSION['error']) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['success'])): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= htmlspecialchars($_SESSION['success']) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['success']); ?>
<?php endif; ?>
<!-- Add User Button -->
<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#addUserModal">
<i class="bi bi-person-plus-fill"></i> Add User
</button>
<!-- Users Table -->
<div class="table-responsive shadow rounded">
<table id="usersTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Username</th>
<th>Role</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= (int)$user['id'] ?></td>
<td><?= htmlspecialchars($user['username']) ?></td>
<td>
<?php if ($user['role'] === 'admin'): ?>
<span class="badge badge-admin">Admin</span>
<?php else: ?>
<span class="badge badge-member">Member</span>
<?php endif; ?>
</td>
<td><?= htmlspecialchars($user['created_at']) ?></td>
<td>
<?php if ($user['id'] !== 1): ?>
<form method="post" class="d-inline" onsubmit="return confirm('Are you sure you want to delete user <?= htmlspecialchars(addslashes($user['username'])) ?>?');">
<input type="hidden" name="delete_user" value="<?= (int)$user['id'] ?>" />
<button type="submit" class="btn btn-sm btn-danger" title="Delete User"><i class="bi bi-trash-fill"></i></button>
</form>
<?php else: ?>
<span class="text-muted">Protected</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- Add User Modal -->
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="addUserModalLabel" aria-hidden="true" style="--bs-modal-width:400px;">
<div class="modal-dialog">
<form method="post" class="modal-content needs-validation" novalidate>
<input type="hidden" name="action" value="add_user" />
<div class="modal-header">
<h5 class="modal-title" id="addUserModalLabel">Add New User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="add-username" class="form-label">Username *</label>
<input type="text" name="username" id="add-username" class="form-control" required />
<div class="invalid-feedback">Please enter a username.</div>
</div>
<div class="mb-3">
<label for="add-password" class="form-label">Password *</label>
<input type="password" name="password" id="add-password" class="form-control" required />
<div class="invalid-feedback">Please enter a password.</div>
</div>
<div class="mb-3">
<label for="add-role" class="form-label">Role *</label>
<select name="role" id="add-role" class="form-select" required>
<option value="member" selected>Member</option>
<option value="admin">Admin</option>
</select>
<div class="invalid-feedback">Please select a role.</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Add User</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div>
</div>
<!-- Bootstrap JS and Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
new simpleDatatables.DataTable("#usersTable");
const forms = document.querySelectorAll('.needs-validation');
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
});
});
});
</script>
</body>
</html>
Key fix:
This line is now correct (insert into password column, not password_hash):
$stmt = $pdo->prepare("INSERT INTO users (username, password, role, created_at) VALUES (?, ?, ?, NOW())");
If your database column is actually named something else, replace password accordingly.
If you want I can also help you generate a database table schema compatible with this code. Just ask!
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
body {
background-color: #f3f6fd;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #344767;
margin: 0;
overflow-y: scroll;
}
a {
text-decoration: none;
}
#sidebar {
position: fixed;
top: 0; bottom: 0; left: 0;
width: 250px;
background-color: #1b1f38;
color: #fff;
display: flex;
flex-direction: column;
padding: 1.5rem 1rem;
box-shadow: 2px 0 12px rgba(27,31,56,0.6);
z-index: 1030;
}
#sidebar .sidebar-brand {
font-size: 1.8rem;
font-weight: 700;
padding-bottom: 1rem;
border-bottom: 1px solid #3a3f67;
margin-bottom: 1.5rem;
letter-spacing: 2px;
user-select: none;
}
#sidebar nav {
flex-grow: 1;
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.7rem 1rem;
color: #a6abc8;
border-radius: 8px;
margin-bottom: 0.8rem;
font-weight: 600;
font-size: 1rem;
transition: background-color 0.25s ease, color 0.25s ease;
user-select: none;
}
#sidebar nav a .bi {
margin-right: 1rem;
font-size: 1.3rem;
}
#sidebar nav a.active,
#sidebar nav a:hover {
background: #5865f2;
color: #fff;
}
#content {
margin-left: 250px;
padding: 2.5rem 3rem;
min-height: 100vh;
}
.top-navbar {
display: flex;
justify-content: flex-end;
align-items: center;
padding-bottom: 2rem;
gap: 1rem;
}
.top-navbar span {
font-weight: 600;
font-size: 1rem;
color: #344767;
}
.stat-card {
position: relative;
background: linear-gradient(135deg, #6e8efb, #a777e3);
color: #fff;
border-radius: 20px;
padding: 2rem 2.5rem;
box-shadow: 0 12px 20px rgba(110,142,251,.4);
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: default;
}
.stat-card:hover {
transform: translateY(-10px);
box-shadow: 0 18px 30px rgba(110,142,251,.6);
}
.stat-icon {
position: absolute;
top: 30px;
right: 30px;
font-size: 4rem;
opacity: 0.12;
user-select: none;
}
.stat-title {
font-weight: 700;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.1em;
opacity: 0.8;
margin-bottom: 0.8rem;
user-select: none;
}
.stat-value {
font-size: 2.8rem;
font-weight: 800;
user-select: text;
}
table {
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0,0,0,0.05);
overflow: hidden;
}
table thead {
background-color: #5865f2 !important;
color: white !important;
font-weight: 600 !important;
}
table thead th, table tbody td {
vertical-align: middle !important;
}
table tbody tr:hover {
background-color: #ecefff;
transition: background-color 0.25s ease;
}
.btn-primary:hover {
filter: brightness(110%);
box-shadow: 0 10px 25px rgba(99,102,241,0.45);
transform: translateY(-3px);
}
</style>
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-brand">Library</div>
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Main Content -->
<main id="content" class="container-fluid">
<div class="top-navbar mb-4">
<span>Welcome, <?= htmlspecialchars($_SESSION['username']) ?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-sm">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</div>
<!-- Stats Cards -->
<div class="row g-4 mb-5">
<div class="col-md-3">
<div class="stat-card">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#4ade80,#16a34a);">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#facc15,#ca8a04);">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#ef4444,#b91c1c);">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</div>
</div>
</div>
<!-- Recent Borrow Records Table -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Recent Borrow Records</h3>
<div class="table-responsive shadow rounded">
<table id="recentBorrowsTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th><th>User</th><th>Book</th><th>Borrow Date</th><th>Due Date</th><th>Return Date</th><th>Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBorrows as $borrow): ?>
<tr>
<td><?= (int)$borrow['id'] ?></td>
<td><?= htmlspecialchars($borrow['username']) ?></td>
<td><?= htmlspecialchars($borrow['title']) ?></td>
<td><?= htmlspecialchars($borrow['borrow_date']) ?></td>
<td><?= htmlspecialchars($borrow['due_date']) ?></td>
<td><?= $borrow['return_date'] ? htmlspecialchars($borrow['return_date']) : '-' ?></td>
<td><?= $borrow['fine'] !== null && $borrow['fine'] > 0 ? '$' . number_format($borrow['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">View All Borrow Records</a>
</section>
<!-- Users Summary -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Users</h3>
<p>Total users registered: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary">
<i class="bi bi-people"></i> Manage Users
</a>
</section>
<!-- Books Summary -->
<section>
<h3 class="fw-semibold mb-3">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg">
<i class="bi bi-book-fill"></i> Manage Books
</a>
</section>
</main>
<!-- Bootstrap JS and Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Initialize DataTables for recent borrow records table
new simpleDatatables.DataTable("#recentBorrowsTable");
});
</script>
Got it! You want a cleaner, advanced, modern-looking dashboard UI that’s more professional and polished, with better spacing, typography, colors, icons, and subtle animations — but maintaining your existing functionality.
Below I provide a full updated admin dashboard code , with:
Smooth sidebar with subtle gradient
Lightweight topbar with user menu dropdown & logout
Modern card styles with color-coded stat cards
Clean and spacious tables with striped rows and hover effect
Responsive layout with good padding/margins and well-structured typography
Use of Bootstrap 5 utilities and custom CSS for consistent styling
Accessibility improvements
SimpleDataTables integration for table sorting/searching
You can replace your current dashboard with this code:
<?php
session_start();
// Logout handler
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
session_destroy();
header('Location: login.php');
exit;
}
// Check admin session
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit;
}
require 'config.php';
try {
$pdo = new PDO("mysql:host=localhost;dbname=library_db;charset=utf8mb4", 'root', 'root', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
die('Database connection failed: ' . htmlspecialchars($e->getMessage()));
}
// Fetch stats
$totalUsers = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$totalBooks = $pdo->query("SELECT COUNT(*) FROM books")->fetchColumn();
$totalBorrowed = $pdo->query("SELECT COUNT(*) FROM borrow_records WHERE return_date IS NULL")->fetchColumn();
$totalAdmins = $pdo->query("SELECT COUNT(*) FROM users WHERE role='admin'")->fetchColumn();
// Fetch recent borrows (last 5)
$recentBorrows = $pdo->query("
SELECT br.id, u.username, b.title, br.borrow_date, br.due_date, br.return_date, br.fine
FROM borrow_records br
JOIN users u ON br.user_id = u.id
JOIN books b ON br.book_id = b.id
ORDER BY br.borrow_date DESC
LIMIT 5
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Admin Dashboard - Library LMS</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables CSS -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
body {
background-color: #f8fafc;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #2e3a59;
margin: 0;
min-height: 100vh;
overflow-x: hidden;
}
/* Sidebar */
#sidebar {
position: fixed;
top: 0; bottom: 0; left: 0;
width: 260px;
background: linear-gradient(160deg, #5a67d8, #434190);
display: flex;
flex-direction: column;
padding: 2rem 1.5rem;
box-shadow: 3px 0 15px rgba(66, 65, 118, 0.5);
z-index: 1050;
}
#sidebar .brand {
font-size: 2rem;
font-weight: 900;
color: #e2e8f0;
text-align: center;
letter-spacing: 4px;
margin-bottom: 2rem;
user-select: none;
text-shadow: 0 0 6px rgba(255 255 255 / 0.2);
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.85rem 1rem;
color: #cbd5e1;
font-weight: 600;
font-size: 1.1rem;
border-radius: 12px;
margin-bottom: 0.9rem;
transition: background-color 0.3s ease, color 0.3s ease;
user-select: none;
gap: 1rem;
}
#sidebar nav a:hover, #sidebar nav a.active {
background: #6875f5;
color: #fff;
box-shadow: 0 0 12px #6875f5bb;
}
#sidebar nav a i {
font-size: 1.4rem;
}
/* Main content area */
#content {
margin-left: 260px;
padding: 3rem 3rem 4rem;
min-height: 100vh;
transition: margin-left 0.3s ease;
}
/* Top navbar */
.top-navbar {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 1.4rem;
margin-bottom: 2.5rem;
}
.top-navbar span {
font-weight: 600;
font-size: 1.1rem;
color: #2e3a59;
user-select: none;
}
.top-navbar .btn-logout {
border-radius: 50px;
padding: 0.3rem 1.1rem;
font-weight: 600;
font-size: 0.95rem;
}
.top-navbar .btn-logout:hover {
background-color: #5a67d8;
color: #fff;
box-shadow: 0 0 8px #5a67d880;
transform: translateY(-2px);
transition: all 0.25s ease;
}
/* Stats Cards */
.stats-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 1.8rem 2.5rem;
margin-bottom: 3rem;
}
.stat-card {
position: relative;
background-color: #fff;
border-radius: 1.2rem;
padding: 2.3rem 2.7rem;
box-shadow:
0 1.5px 3.5px rgb(0 0 0 / 0.05),
0 5px 15px rgb(0 0 0 / 0.1);
color: #374151;
cursor: default;
transition: box-shadow 0.3s ease, transform 0.25s ease;
}
.stat-card:hover {
box-shadow:
0 4px 25px rgb(90 103 216 / 0.3),
0 12px 45px rgb(90 103 216 / 0.27);
transform: translateY(-8px);
}
.stat-icon {
position: absolute;
font-size: 4.5rem;
opacity: 0.1;
right: 2rem;
top: 1.7rem;
user-select: none;
color: #64748b;
}
.stat-card.users .stat-icon { color: #4f46e5; }
.stat-card.books .stat-icon { color: #16a34a; }
.stat-card.borrowed .stat-icon { color: #ca8a04; }
.stat-card.admins .stat-icon { color: #dc2626; }
.stat-title {
text-transform: uppercase;
font-weight: 700;
letter-spacing: 0.12em;
font-size: 0.82rem;
margin-bottom: 0.7rem;
color: #6b7280;
user-select: none;
}
.stat-value {
font-size: 3.3rem;
font-weight: 800;
color: #111827;
user-select: text;
}
/* Tables */
.table-section {
background-color: #fff;
border-radius: 16px;
box-shadow: 0 12px 30px rgb(0 0 0 / 0.04);
padding: 2rem;
overflow-x: auto;
margin-bottom: 3rem;
}
table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
table-layout: fixed;
}
thead th {
background-color: #4f46e5 !important;
color: white !important;
font-weight: 700 !important;
font-size: 1rem;
padding: 1rem 1.3rem;
text-align: left;
user-select: none;
}
tbody td {
background: white;
padding: 0.9rem 1.3rem;
font-size: 0.95rem;
font-weight: 600;
color: #374151;
vertical-align: middle;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
border-bottom: 1px solid #e4e7f0;
}
tbody tr:hover {
background-color: #eef2ff;
}
/* Section headings */
h3 {
font-size: 1.8rem;
font-weight: 700;
color: #374151;
margin-bottom: 1.5rem;
}
/* Buttons */
.btn-primary {
background-color: #4f46e5;
border: none;
font-weight: 700;
font-size: 1.05rem;
padding: 0.55rem 1.6rem;
border-radius: 12px;
transition: background-color 0.3s ease, box-shadow 0.3s ease;
display: inline-flex;
align-items: center;
gap: 0.6rem;
}
.btn-primary:hover {
background-color: #4338ca;
box-shadow: 0 12px 25px rgba(79, 70, 229, 0.3);
transform: translateY(-2px);
}
.btn-primary i {
font-size: 1.3rem;
}
/* Responsive adjustments */
@media (max-width: 992px) {
#sidebar { width: 220px; }
#content { margin-left: 220px; padding: 2rem 2rem 3rem; }
.stat-card { padding: 1.75rem 2rem; }
.stat-icon { font-size: 4rem; top: 1.3rem; right: 1.6rem; }
}
@media (max-width: 680px) {
#sidebar {
position: relative;
width: 100%;
height: auto;
box-shadow: none;
padding: 1rem 1rem;
display: flex;
justify-content: center;
}
#content { margin-left: 0; padding: 1.5rem; }
.stat-card { padding: 1.2rem 1.4rem; }
.stat-icon { display: none; }
}
</style>
</head>
<body>
<!-- Sidebar -->
<nav id="sidebar" role="navigation" aria-label="Main sidebar">
<div class="brand">Library LMS</div>
<nav aria-label="Sidebar navigation">
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Main content -->
<main id="content" tabindex="-1">
<header class="top-navbar">
<span>Welcome, <?= htmlspecialchars($_SESSION['username']) ?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-logout">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</header>
<!-- Stats Cards -->
<section class="stats-row" aria-label="Summary statistics">
<article class="stat-card users" tabindex="0" aria-label="Total users: <?= $totalUsers ?>">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</article>
<article class="stat-card books" tabindex="0" aria-label="Total books: <?= $totalBooks ?>">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</article>
<article class="stat-card borrowed" tabindex="0" aria-label="Currently borrowed books: <?= $totalBorrowed ?>">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</article>
<article class="stat-card admins" tabindex="0" aria-label="Total admin users: <?= $totalAdmins ?>">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</article>
</section>
<!-- Recent Borrow Records -->
<section aria-labelledby="recent-borrows" class="table-section">
<h3 id="recent-borrows">Recent Borrow Records</h3>
<table id="recentBorrowsTable" class="table table-striped" aria-describedby="recent-borrows-desc">
<caption id="recent-borrows-desc" class="visually-hidden">5 most recent borrow records including user, book, dates, and fines</caption>
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">User</th>
<th scope="col">Book</th>
<th scope="col">Borrow Date</th>
<th scope="col">Due Date</th>
<th scope="col">Return Date</th>
<th scope="col">Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBorrows as $b): ?>
<tr>
<td><?= (int)$b['id'] ?></td>
<td><?= htmlspecialchars($b['username']) ?></td>
<td><?= htmlspecialchars($b['title']) ?></td>
<td><?= htmlspecialchars($b['borrow_date']) ?></td>
<td><?= htmlspecialchars($b['due_date']) ?></td>
<td><?= $b['return_date'] ? htmlspecialchars($b['return_date']) : '-' ?></td>
<td><?= $b['fine'] && $b['fine'] > 0 ? '$'.number_format($b['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="borrow_records.php" class="btn btn-primary mt-3" aria-label="View all borrow records">
View All Borrow Records <i class="bi bi-arrow-right"></i>
</a>
</section>
<!-- Users Summary -->
<section class="mb-5">
<h3 class="fw-semibold mb-3">Users</h3>
<p class="fs-5">Total users registered: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary d-flex align-items-center gap-2" aria-label="Manage users">
<i class="bi bi-people-fill fs-5"></i> Manage Users
</a>
</section>
<!-- Books Summary -->
<section>
<h3 class="fw-semibold mb-3">Books Inventory</h3>
<p class="fs-5">Total books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg d-flex align-items-center gap-2" aria-label="Manage books">
<i class="bi bi-book-fill fs-4"></i> Manage Books
</a>
</section>
</main>
<!-- Bootstrap JS and Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
new simpleDatatables.DataTable("#recentBorrowsTable", {
searchable: true,
perPage: 5,
fixedHeight: true
});
});
</script>
</body>
</html>
Why this is improved:
Clear, consistent font sizes + spacing for readability
Sidebar uses a nice gradient and subtle box shadows
Stats cards use white backgrounds with subtle shadows and prominent icons
Table is fully responsive, elegant, and has a descriptive caption for accessibility
Buttons have distinct colors and subtle hover animations
Layout is responsive, with mobile friendliness baked in
Uses mostly Bootstrap 5 utilities, minimal custom CSS for easy maintainability
Feel free to copy this entire file as your new admin_dashboard.php.
Let me know if you want me to help with dark mode or any other page!
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
body {
background-color: #f3f6fd;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #344767;
margin: 0;
overflow-y: scroll;
}
a {
text-decoration: none;
}
#sidebar {
position: fixed;
top: 0; bottom: 0; left: 0;
width: 250px;
background-color: #1b1f38;
color: #fff;
display: flex;
flex-direction: column;
padding: 1.5rem 1rem;
box-shadow: 2px 0 12px rgba(27,31,56,0.6);
z-index: 1030;
}
#sidebar .sidebar-brand {
font-size: 1.8rem;
font-weight: 700;
padding-bottom: 1rem;
border-bottom: 1px solid #3a3f67;
margin-bottom: 1.5rem;
letter-spacing: 2px;
user-select: none;
}
#sidebar nav {
flex-grow: 1;
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.7rem 1rem;
color: #a6abc8;
border-radius: 8px;
margin-bottom: 0.8rem;
font-weight: 600;
font-size: 1rem;
transition: background-color 0.25s ease, color 0.25s ease;
user-select: none;
}
#sidebar nav a .bi {
margin-right: 1rem;
font-size: 1.3rem;
}
#sidebar nav a.active,
#sidebar nav a:hover {
background: #5865f2;
color: #fff;
}
#content {
margin-left: 250px;
padding: 2.5rem 3rem;
min-height: 100vh;
}
.top-navbar {
display: flex;
justify-content: flex-end;
align-items: center;
padding-bottom: 2rem;
gap: 1rem;
}
.top-navbar span {
font-weight: 600;
font-size: 1rem;
color: #344767;
}
.stat-card {
position: relative;
background: linear-gradient(135deg, #6e8efb, #a777e3);
color: #fff;
border-radius: 20px;
padding: 2rem 2.5rem;
box-shadow: 0 12px 20px rgba(110,142,251,.4);
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: default;
}
.stat-card:hover {
transform: translateY(-10px);
box-shadow: 0 18px 30px rgba(110,142,251,.6);
}
.stat-icon {
position: absolute;
top: 30px;
right: 30px;
font-size: 4rem;
opacity: 0.12;
user-select: none;
}
.stat-title {
font-weight: 700;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.1em;
opacity: 0.8;
margin-bottom: 0.8rem;
user-select: none;
}
.stat-value {
font-size: 2.8rem;
font-weight: 800;
user-select: text;
}
table {
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0,0,0,0.05);
overflow: hidden;
}
table thead {
background-color: #5865f2 !important;
color: white !important;
font-weight: 600 !important;
}
table thead th, table tbody td {
vertical-align: middle !important;
}
table tbody tr:hover {
background-color: #ecefff;
transition: background-color 0.25s ease;
}
.btn-primary:hover {
filter: brightness(110%);
box-shadow: 0 10px 25px rgba(99,102,241,0.45);
transform: translateY(-3px);
}
</style>
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-brand">Library</div>
<nav>
<a href="#" class="active"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Main Content -->
<main id="content" class="container-fluid">
<div class="top-navbar mb-4">
<span>Welcome, <?= htmlspecialchars($_SESSION['username']) ?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-sm">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</div>
<!-- Stats Cards -->
<div class="row g-4 mb-5">
<div class="col-md-3">
<div class="stat-card">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#4ade80,#16a34a);">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#facc15,#ca8a04);">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card" style="background: linear-gradient(135deg,#ef4444,#b91c1c);">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</div>
</div>
</div>
<!-- Recent Borrow Records Table -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Recent Borrow Records</h3>
<div class="table-responsive shadow rounded">
<table id="recentBorrowsTable" class="table table-striped table-hover align-middle">
<thead class="table-primary">
<tr>
<th>ID</th><th>User</th><th>Book</th><th>Borrow Date</th><th>Due Date</th><th>Return Date</th><th>Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBorrows as $borrow): ?>
<tr>
<td><?= (int)$borrow['id'] ?></td>
<td><?= htmlspecialchars($borrow['username']) ?></td>
<td><?= htmlspecialchars($borrow['title']) ?></td>
<td><?= htmlspecialchars($borrow['borrow_date']) ?></td>
<td><?= htmlspecialchars($borrow['due_date']) ?></td>
<td><?= $borrow['return_date'] ? htmlspecialchars($borrow['return_date']) : '-' ?></td>
<td><?= $borrow['fine'] !== null && $borrow['fine'] > 0 ? '$' . number_format($borrow['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">View All Borrow Records</a>
</section>
<!-- Users Summary -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Users</h3>
<p>Total users registered: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary">
<i class="bi bi-people"></i> Manage Users
</a>
</section>
<!-- Books Summary -->
<section>
<h3 class="fw-semibold mb-3">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg">
<i class="bi bi-book-fill"></i> Manage Books
</a>
</section>
</main>
<!-- Bootstrap JS and Simple DataTables -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Initialize DataTables for recent borrow records table
new simpleDatatables.DataTable("#recentBorrowsTable");
});
</script>
Certainly! To remove vertical scrolling caused by the body and overall page overflow, we can make sure the layout fits within the viewport height (100vh), use flexible containers, and, if content exceeds, allow internal scrolls where appropriate (e.g., tables inside a container with a fixed max height).
Below is your full updated code with:
No vertical scrolling on body (overflow-y: hidden)
Content area uses flex layout to expand and show all content (or scroll inside tables)
Responsive improvements and some minor UI polish
Table container with vertical scroll if needed (instead of page scroll)
Sidebar fixed height 100vh
Minimum page height using flexbox on body/html for full viewport usage
<?php
session_start();
// Logout handler
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
session_destroy();
header('Location: login.php');
exit;
}
// Check if user is logged in and is admin
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit;
}
require 'config.php';
try {
$pdo = new PDO("mysql:host=localhost;dbname=library_db;charset=utf8mb4", 'root', 'root', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
die('Database connection failed: ' . htmlspecialchars($e->getMessage()));
}
// Fetch stats from database
$totalUsers = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$totalBooks = $pdo->query("SELECT COUNT(*) FROM books")->fetchColumn();
$totalBorrowed = $pdo->query("SELECT COUNT(*) FROM borrow_records WHERE return_date IS NULL")->fetchColumn();
$totalAdmins = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'admin'")->fetchColumn();
// Fetch recent borrow records (limit 5)
$recentBorrows = $pdo->query("
SELECT br.id, u.username, b.title, br.borrow_date, br.due_date, br.return_date, br.fine
FROM borrow_records br
JOIN users u ON br.user_id = u.id
JOIN books b ON br.book_id = b.id
ORDER BY br.borrow_date DESC
LIMIT 5
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Admin Dashboard - Library LMS</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Simple DataTables -->
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.css" rel="stylesheet" />
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow-y: hidden; /* Remove vertical page scroll */
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f3f6fd;
color: #344767;
}
body {
display: flex;
height: 100vh;
overflow: hidden;
}
#sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
width: 250px;
background-color: #1b1f38;
color: #fff;
display: flex;
flex-direction: column;
padding: 1.5rem 1rem;
box-shadow: 2px 0 12px rgba(27,31,56,0.6);
z-index: 1030;
user-select: none;
}
#sidebar .sidebar-brand {
font-size: 1.8rem;
font-weight: 700;
padding-bottom: 1rem;
border-bottom: 1px solid #3a3f67;
margin-bottom: 1.5rem;
letter-spacing: 2px;
}
#sidebar nav {
flex-grow: 1;
display: flex;
flex-direction: column;
}
#sidebar nav a {
display: flex;
align-items: center;
padding: 0.7rem 1rem;
color: #a6abc8;
border-radius: 8px;
margin-bottom: 0.8rem;
font-weight: 600;
font-size: 1rem;
transition: background-color 0.25s ease, color 0.25s ease;
}
#sidebar nav a .bi {
margin-right: 1rem;
font-size: 1.3rem;
}
#sidebar nav a.active,
#sidebar nav a:hover {
background: #5865f2;
color: #fff;
}
#content {
margin-left: 250px;
padding: 2.5rem 3rem;
min-height: 100vh;
height: 100%;
overflow-y: auto; /* Scroll inside content */
box-sizing: border-box;
display: flex;
flex-direction: column;
}
.top-navbar {
display: flex;
justify-content: flex-end;
align-items: center;
padding-bottom: 2rem;
gap: 1rem;
flex-shrink: 0;
}
.top-navbar span {
font-weight: 600;
font-size: 1rem;
color: #344767;
}
.stat-card {
position: relative;
background: linear-gradient(135deg, #6e8efb, #a777e3);
color: #fff;
border-radius: 20px;
padding: 2rem 2.5rem;
box-shadow: 0 12px 20px rgba(110,142,251,.4);
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: default;
}
.stat-card:hover {
transform: translateY(-10px);
box-shadow: 0 18px 30px rgba(110,142,251,.6);
}
.stat-icon {
position: absolute;
top: 30px;
right: 30px;
font-size: 4rem;
opacity: 0.12;
user-select: none;
}
.stat-title {
font-weight: 700;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.1em;
opacity: 0.8;
margin-bottom: 0.8rem;
user-select: none;
}
.stat-value {
font-size: 2.8rem;
font-weight: 800;
user-select: text;
}
/* Different colors for separate cards */
.stat-card.users {
background: linear-gradient(135deg, #5a67d8, #4c51bf);
}
.stat-card.books {
background: linear-gradient(135deg, #16a34a, #15803d);
}
.stat-card.borrowed {
background: linear-gradient(135deg, #ca8a04, #a16207);
}
.stat-card.admins {
background: linear-gradient(135deg, #dc2626, #991b1b);
}
.row.g-4.mb-5 {
flex-shrink: 0;
}
/* Table container with scroll inside content area */
.table-container {
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0,0,0,0.05);
padding: 1.5rem 1rem;
overflow-x: auto;
max-height: 440px;
margin-bottom: 1.5rem;
}
table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
table-layout: fixed;
}
thead {
background-color: #5865f2 !important;
color: white !important;
font-weight: 600 !important;
}
thead th, tbody td {
vertical-align: middle !important;
padding: 0.8rem 1rem;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
tbody tr:hover {
background-color: #ecefff;
transition: background-color 0.25s ease;
cursor: default;
}
/* Buttons */
a.btn {
user-select: none;
}
a.btn-primary:hover {
filter: brightness(110%);
box-shadow: 0 10px 25px rgba(99,102,241,0.45);
transform: translateY(-3px);
transition: all 0.25s ease;
}
</style>
</head>
<body>
<!-- Sidebar -->
<nav id="sidebar" aria-label="Sidebar navigation">
<div class="sidebar-brand">Library</div>
<nav>
<a href="#" class="active" aria-current="page"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a href="borrow_records.php"><i class="bi bi-journal-arrow-up"></i> Borrow Records</a>
<a href="books.php"><i class="bi bi-book"></i> Books</a>
<a href="users.php"><i class="bi bi-people"></i> Users</a>
</nav>
</nav>
<!-- Main content -->
<main id="content" role="main" tabindex="-1">
<div class="top-navbar">
<span>Welcome, <?= htmlspecialchars($_SESSION['username']) ?></span>
<a href="?action=logout" class="btn btn-outline-primary btn-sm">
Logout <i class="bi bi-box-arrow-right"></i>
</a>
</div>
<!-- Stats Cards -->
<div class="row g-4 mb-5">
<div class="col-md-3">
<div class="stat-card users">
<i class="bi bi-people-fill stat-icon"></i>
<p class="stat-title">Total Users</p>
<h2 class="stat-value"><?= $totalUsers ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card books">
<i class="bi bi-book-fill stat-icon"></i>
<p class="stat-title">Total Books</p>
<h2 class="stat-value"><?= $totalBooks ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card borrowed">
<i class="bi bi-journal-arrow-up stat-icon"></i>
<p class="stat-title">Borrowed Books</p>
<h2 class="stat-value"><?= $totalBorrowed ?></h2>
</div>
</div>
<div class="col-md-3">
<div class="stat-card admins">
<i class="bi bi-shield-lock-fill stat-icon"></i>
<p class="stat-title">Admins</p>
<h2 class="stat-value"><?= $totalAdmins ?></h2>
</div>
</div>
</div>
<!-- Recent Borrow Records -->
<section aria-labelledby="recent-borrows-label" class="mb-5">
<h3 id="recent-borrows-label" class="fw-semibold mb-4">Recent Borrow Records</h3>
<div class="table-container shadow rounded" role="region" aria-describedby="recent-borrows-label">
<table id="recentBorrowsTable" class="table table-striped table-hover align-middle" aria-describedby="recent-borrows-desc">
<caption id="recent-borrows-desc" class="visually-hidden">
Table showing 5 most recent borrow records including user, book, borrow and return dates, and fines.
</caption>
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">User</th>
<th scope="col">Book</th>
<th scope="col">Borrow Date</th>
<th scope="col">Due Date</th>
<th scope="col">Return Date</th>
<th scope="col">Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBorrows as $b): ?>
<tr>
<td><?= (int)$b['id'] ?></td>
<td><?= htmlspecialchars($b['username']) ?></td>
<td><?= htmlspecialchars($b['title']) ?></td>
<td><?= htmlspecialchars($b['borrow_date']) ?></td>
<td><?= htmlspecialchars($b['due_date']) ?></td>
<td><?= $b['return_date'] ? htmlspecialchars($b['return_date']) : '-' ?></td>
<td><?= ($b['fine'] && $b['fine'] > 0) ? '$' . number_format($b['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="borrow_records.php" class="btn btn-primary mt-3">
View All Borrow Records
</a>
</section>
<!-- Users Section -->
<section class="mb-5">
<h3 class="fw-semibold mb-4">Users</h3>
<p>Total users registered: <strong><?= $totalUsers ?></strong></p>
<a href="users.php" class="btn btn-primary">
<i class="bi bi-people"></i> Manage Users
</a>
</section>
<!-- Books Section -->
<section>
<h3 class="fw-semibold mb-3">Books Inventory</h3>
<p class="fs-5">Total Books: <strong><?= $totalBooks ?></strong></p>
<a href="books.php" class="btn btn-success btn-lg">
<i class="bi bi-book-fill"></i> Manage Books
</a>
</section>
</main>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- SimpleDataTables -->
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/simple-datatables.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
new simpleDatatables.DataTable("#recentBorrowsTable", {
searchable: true,
fixedHeight: true,
perPage: 5
});
});
</script>
</body>
</html>
Summary of changes:
body and html use full height and no vertical scroll.
Sidebar is fixed height 100vh.
Main content area (#content) fills the rest of viewport and scrolls internally.
The "Recent Borrow Records" table container has max height and vertical scroll if needed (keeps page compact).
Simple, modern color-coded stat cards.
Improved semantics and accessibility.
If you want me to help with making sidebar collapsible on smaller screens or add dark mode, just ask!
The issue you're seeing—where the table displays column headers ("Table showing... ID User Book...") and then showing your data rows but the numbering or layout looks off—typically happens when you view the HTML page in a way that exposes the table markup literally , such as:
Opening the .php file directly in a browser instead of running it through your PHP server
Or the PHP code is not actually executed (PHP not interpreted), so the raw output shows
How do you normally test the page?
Make sure:
You access the page through your local web server with PHP installed (e.g., http://localhost/library_lms/admin_dashboard.php)
You do not open the PHP file directly as a file (file:///C:/xampp/htdocs/.../admin_dashboard.php)
Why does this matter?
PHP runs on the server (like Apache/Xampp), processes the PHP code, outputs HTML.
If you open the file directly in the browser as a file, it won't run PHP and will show raw code or parts of it.
That causes headers and HTML elements to mix, not render as a proper table.
What else to check
File extension: your file should be .php, not .html
Server running: your local server (e.g., XAMPP, WampServer, MAMP) must be running
Visit through server URL: access as http://localhost/library_lms/admin_dashboard.php, not from file browser.
If you see plain text or weird formatting in the table
Two possibilities:
The PHP code is outputting a caption tag contents (which is the description text for the table) as visible text because the browser is showing it literally.
Or your browser's default styles show the table caption before the table, which is normal, but you might have added an intentionally descriptive caption for accessibility.
Regarding your actual question:
"Table showing 5 most recent borrow records including user, book, borrow and return dates, and fines. ID User Book Borrow Date Due Date Return Date Fine 5 aryan Pride and Prejudice 2025-04-23 2025-05-07 - -"
The text "Table showing 5 most recent..." is a <caption> to describe your table — this is good for accessibility.
If you want to hide the caption visually but keep it for screen readers (which is recommended) , use CSS:
caption {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
overflow: hidden;
clip: rect(0 0 0 0);
clip-path: inset(50%);
white-space: nowrap;
border: 0;
padding: 0;
}
This style visually hides the caption but it remains readable by assistive technologies.
Example snippet:
Add this CSS to your style block:
caption {
position: absolute;
width: 1px !important;
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0 0 0 0) !important;
clip-path: inset(50%) !important;
white-space: nowrap !important;
border: 0 !important;
padding: 0 !important;
}
Why keep the caption?
Improves accessibility for screen reader users
Helps identify the table purpose without cluttering the UI
Summary
Access your PHP page via web server (localhost URL), not directly as file
Use CSS to visually hide <caption> if you don't want that description visible but keep it for screen readers
Confirm the data outputs inside the table are correct and align visually based on your CSS/table styles
If you want, here’s your relevant HTML snippet with caption and CSS included to hide caption visually but keep accessible:
<style>
caption {
position: absolute;
width: 1px !important;
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0 0 0 0) !important;
clip-path: inset(50%) !important;
white-space: nowrap !important;
border: 0 !important;
padding: 0 !important;
}
</style>
<table aria-describedby="recent-borrows-desc" id="recentBorrowsTable" class="table table-striped table-hover align-middle">
<caption id="recent-borrows-desc">
Table showing 5 most recent borrow records including user, book, borrow and return dates, and fines.
</caption>
<thead>
<tr>
<th>ID</th><th>User</th><th>Book</th><th>Borrow Date</th><th>Due Date</th><th>Return Date</th><th>Fine</th>
</tr>
</thead>
<tbody>
<!-- your PHP generated rows -->
</tbody>
</table>
Let me know if you want me to help fix your full code with this fix!
id
it's not a sequential row number
Why IDs look like this?
These IDs come from your database column id (i.e., br.id), which is a unique record identifier and not necessarily sequential in the result set order.
Your SQL orders by borrow date DESC, so records are sorted by date, not by ID order.
Your data might be inserted sporadically; hence IDs like 5 appearing before 2 is normal if the record with ID=5 has a later borrow_date than ID=2.
How to show sequential numbering instead of actual IDs? If you want the table to show:
| # | User | Book | ... |
where # is simply row number 1, 2, 3, 4, 5, irrespective of ID, you should generate that in PHP, for example:
<?php
$counter = 1; // initial number
foreach ($recentBorrows as $borrow):
?>
<tr>
<td><?= $counter++ ?></td>
<!-- other columns -->
</tr>
<?php endforeach; ?>
Example replacing your ID column: Replace this line in your <tbody>:
<td><?= (int)$borrow['id'] ?></td>
<td><?= $counter++ ?></td>
and initialize $counter = 1; before the foreach loop:
<tbody>
<?php
$counter = 1;
foreach ($recentBorrows as $borrow):
?>
<tr>
<td><?= $counter++ ?></td>
<td><?= htmlspecialchars($borrow['username']) ?></td>
<td><?= htmlspecialchars($borrow['title']) ?></td>
<td><?= htmlspecialchars($borrow['borrow_date']) ?></td>
<td><?= htmlspecialchars($borrow['due_date']) ?></td>
<td><?= $borrow['return_date'] ? htmlspecialchars($borrow['return_date']) : '-' ?></td>
<td><?= ($borrow['fine'] && $borrow['fine'] > 0) ? '$'.number_format($borrow['fine'], 2) : '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
Summary & Suggestion Problem Reason Fix (if you want) ID not sequential Using actual database record primary key Use PHP $counter=1 loop to show row numbers
If you want, I can provide your full dashboard or table snippet updated with this numbering fix included — just ask!
Copy first response
Not yet included in a published release.