Projects›Core· 180 min read
Project: PHP CRUD App
Build a complete database-driven app — list, add, edit and delete records — with plain PHP and MySQL.
What you will learn
- Build full CRUD with PHP + MySQL
- Handle forms and validation
- Structure a multi-file app
The brief
Build a small manager app (tasks, contacts, products) where users can list, add, edit and delete records stored in MySQL.
- A MySQL table for your resource.
- A page that lists all records from the database.
- A form to add a record (with validation).
- Edit and delete for each record.
- PDO with prepared statements throughout.
- A shared header/footer via
include.
Work through the CRUD steps in this order — each one builds on the last, so the app keeps working at every stage:
- Set up the database: create the table (for example
taskswithid,title,done) and aconfig.phpthat opens a PDO connection (the connect lesson). - Build the shared header/footer: make
header.phpandfooter.phpandincludethem on every page so all pages share one layout. - READ (list): write the listing page that runs
SELECT * FROM tasksand loops the rows withforeachto show them in a table. - CREATE (add): build an HTML form that posts to an
addscript, validate the input, thenINSERTwith a prepared statement and redirect back to the list. - UPDATE (edit): link each row to an
editpage that loads that record byid, shows it pre-filled in a form, andUPDATEs it with a prepared statement on submit. - DELETE: add a delete link per row that passes the
idto adeletescript which runs a preparedDELETE ... WHERE id = ?, then returns to the list. - Secure everything: confirm every query uses
?placeholders, and wrap any user text you print inhtmlspecialchars().
Note: Each numbered step maps to one letter of CRUD plus the plumbing around it: step 1 is the connection, steps 3–6 are Read, Create, Update and Delete, and steps 2 and 7 are the structure and safety that hold it together.
Tip: Build one operation at a time: get listing working, then add, then edit, then delete. A small app that fully works beats a big unfinished one.
✍️ Practice
- Build the full CRUD app meeting all six requirements.
- Test every operation in the browser.
🏠 Homework
- Add a search box that filters the list using a prepared LIKE query.