Project overview
The Library Information System gives a librarian one place to manage the book catalog. Each book is stored with its title, author, category and number of copies, and every action, from adding a new title to removing an old one, has its own focused page. The list shows the newest books first, so recent additions are always easy to find.
Problem it solves
Small school and community libraries often keep their catalog in notebooks or spreadsheets, where it is hard to see what is on the shelf and easy to record impossible values such as negative or fractional copy counts.
Key features
- Full catalog management: add, list, view, edit and delete books
- Newest books first, with View, Edit and Delete actions on every row
- Copy counts accepted only as whole numbers, with zero allowed for titles with no copies on hand
- A confirmation page before any book is deleted
- A clear Record not found page for missing or invalid book IDs
Case-specific rule
Copies must be a whole number of zero or more
Zero is valid, so a title can stay in the catalog with no copies on hand. Negative numbers, decimals and values with leading zeros are rejected on the server.
Database design
Database library_db, table books, InnoDB with utf8mb4.
| Column | Type | Rule |
|---|---|---|
| id | INT AUTO_INCREMENT | Primary key, generated automatically. |
| title | VARCHAR(150) | Required. Up to 150 characters. |
| author | VARCHAR(100) | Required. Up to 100 characters. |
| category | VARCHAR(50) | Required. Up to 50 characters. |
| copies | INT | Required. A whole number of zero or more. |
From the code
The validation behind this case, exactly as written in create.php.
if ($values['copies'] === '') $errors[] = 'Number of Copies is required.';
if (!preg_match('/^(0|[1-9][0-9]*)$/', $values['copies'])) {
$errors[] = 'Copies must be a whole number greater than or equal to zero.';
}Challenges and solutions
01
Zero is valid, negatives are not
Challenge encountered
The catalog had to accept zero copies for titles with none on hand, while still rejecting negative numbers, decimals and malformed values like 007.
Solution implemented
A strict server-side pattern, ^(0|[1-9][0-9]*)$, checks the copy count on both create and edit, so only clean whole numbers reach the INT column.
02
Keeping typed text safe on screen
Challenge encountered
Titles and author names are free text, so a title containing HTML could break the page or run a script.
Solution implemented
Every value is escaped with htmlspecialchars, using ENT_QUOTES and UTF-8, on the list, detail and confirmation pages.
Outcome and impact
A complete, validated catalog workflow delivered in the required eight-file format, with three sample books ready to import through phpMyAdmin.
Every PHP file in the project passed syntax checking before submission.
- Files delivered
- 8
- PHP pages
- 6
- Table columns
- 5
- Sample records
- 3
Project files
Delivered in the required eight-file format, ready to drop into XAMPP.
config.phpOpens the PDO connection to the database, with exceptions turned on for errors.index.phpLists every record, newest first, with View, Edit and Delete links on each row.create.phpValidates a new record, saves it with a prepared INSERT, then redirects to the list.view.phpShows one record after checking that its ID is a positive whole number.edit.phpLoads an existing record, validates the changes and saves them with a prepared UPDATE.delete.phpShows a confirmation page, then deletes the record only on a confirmed POST.database.sqlCreates the database and table, then inserts three fictional sample records.README.mdSetup steps for XAMPP and phpMyAdmin, plus the feature list and local URL.
Secure by default
The same six practices protect all five examination cases.
- Prepared statementsEvery query runs through PDO prepared statements with named placeholders, so typed input never becomes part of the SQL.
- Escaped outputEvery value passes through htmlspecialchars with ENT_QUOTES and UTF-8 before it reaches the page, which blocks script injection.
- POST-only changesCreating, editing and deleting only happen on POST requests, and a delete needs an explicit confirmation first.
- Safe record IDsIDs must be positive whole numbers. A missing or invalid record returns a 404 with a clear Record not found page.
- Post, redirect, getAfter a successful save the page redirects to the list, so refreshing the browser never submits the form twice.
- Helpful validationFailed saves list every problem at once and keep what was typed, so nobody has to fill in the form again.
See it working
Add, edit and delete records in the live demo, and watch each prepared statement as it runs.