A fully functional web-based Library Management System to replace Excel-based workflows. Manages books inventory, borrowers, borrowing/return transactions, and analytics.
- XAMPP (Windows) or LAMP/MAMP (Linux/Mac)
- PHP 8.0+
- MySQL 5.7+ / MariaDB 10.3+
- Web browser (Chrome, Firefox, Edge)
Copy the `library-system/` folder to your web server root:
- XAMPP (Windows): C:\xampp\htdocs\library-system\
- LAMP (Linux): /var/www/html/library-system/
- MAMP (Mac): /Applications/MAMP/htdocs/library-system/
- Open phpMyAdmin: http://localhost/phpmyadmin
- Click "New" to create a database (or let the SQL script do it)
- Click "Import" tab
- Choose
database.sqlfrom the project root - Click "Go"
OR via MySQL CLI:
mysql -u root -p < database.sqlEdit config/database.php:
define('DB_HOST', 'localhost'); // Usually 'localhost'
define('DB_USER', 'root'); // Your MySQL username
define('DB_PASS', ''); // Your MySQL password (empty for XAMPP default)
define('DB_NAME', 'library_db'); // Database nameEdit config/app.php:
define('BASE_URL', 'http://localhost/library-system');Change this if your setup uses a different port or path.
Open your browser and go to:
http://localhost/library-system
Username: admin
Password: Library@2024
library-system/
βββ config/
β βββ app.php # App settings (BASE_URL, timezone, session)
β βββ database.php # Database connection (PDO)
βββ includes/
β βββ header.php # HTML head + CSS links
β βββ sidebar.php # Navigation sidebar
β βββ footer.php # JS scripts
β βββ helpers.php # Utility functions (sanitize, badge, paginate, etc.)
βββ auth/
β βββ login.php # Login page
β βββ logout.php # Logout handler
β βββ hash.php # Password hash generator utility
βββ modules/
β βββ books/
β β βββ index.php # Books list (search, filter, paginate, delete)
β β βββ add.php # Add new book
β β βββ edit.php # Edit book
β βββ borrowers/
β β βββ index.php # Borrowers list
β β βββ add.php # Add borrower
β β βββ edit.php # Edit borrower
β β βββ history.php # Borrower borrow history
β βββ borrow/
β β βββ index.php # All borrow records (filter, export, paginate)
β β βββ issue.php # Issue (borrow) a book
β β βββ return.php # Return a book
β βββ reports/
β βββ index.php # Reports dashboard (5 report types)
β βββ export.php # CSV export handler
βββ assets/
β βββ css/style.css # Custom CSS (sidebar, cards, tables, print)
β βββ js/app.js # DataTables init, sidebar toggle, confirm dialogs
βββ database.sql # Full database schema + sample data
βββ index.php # Entry point (redirects to dashboard or login)
βββ dashboard.php # Main dashboard with stats + Chart.js charts
- Password hashing: PHP
password_hash()with bcrypt - SQL injection prevention: PDO prepared statements throughout
- XSS prevention:
htmlspecialchars()on all output - Session-based auth: All pages require valid session
- Input validation: Server-side validation on all forms
- Audit logging: All create/update/delete/borrow/return actions logged
- Add, edit, delete books
- Search by title, author, Book ID
- Filter by category and status
- CSV export + print
- Auto-generate suggested Book IDs
- Add, edit, delete borrowers
- View full borrow history per borrower
- Category-based ID suggestions (STU-, TCH-, STF-)
- Filter by category and status
- Issue books (only Available books can be borrowed)
- Automatic book status update on borrow/return
- Overdue detection (> 14 days, configurable via
BORROW_DAYS) - Due date auto-calculated on issue form
- 7 live stat cards
- Bar chart: Borrow trend (last 6 months)
- Doughnut chart: Books by category
- Top 10 borrowed books table
- Overdue books alert list
- Recent transactions
- Borrow Records β filterable by date, book category, borrower category, status
- All Books β inventory report with filters
- Overdue Books β all unreturned books past due date
- Most Borrowed Books β popularity ranking
- Most Active Borrowers β borrower activity ranking
- CSV export with UTF-8 BOM (opens correctly in Excel)
- Print-optimized layout (hides navigation/buttons)
In config/app.php:
define('BORROW_DAYS', 14); // Change to any number- Visit
http://localhost/library-system/auth/hash.php?p=YourNewPassword - Copy the hash
- Insert into
userstable via phpMyAdmin:
INSERT INTO users (username, password, full_name, role)
VALUES ('newadmin', 'PASTE_HASH_HERE', 'New Admin', 'admin');- Delete
auth/hash.phpwhen done.
| Problem | Solution |
|---|---|
| Blank page / errors | Enable PHP error display: add ini_set('display_errors', 1); to config/app.php |
| "DB connection failed" | Check config/database.php credentials |
| Login fails | Regenerate hash using auth/hash.php and update DB |
| CSS not loading | Check BASE_URL in config/app.php |
| Session not persisting | Ensure PHP sessions are enabled and writable |
Install PHPMailer via Composer and create modules/notifications/send_overdue.php
Replace text inputs with a barcode scanner input β most USB scanners act as keyboard input followed by Enter, which works natively with the current form design.
The users table already has a role column (admin/librarian).
Use isAdmin() helper (already defined in helpers.php) to restrict pages.
Free to use for educational and institutional purposes.