A lightweight, secure CRUD (Create, Read, Update, Delete) application built with PHP and MySQL. This application demonstrates fundamental web development concepts with proper security practices, allowing users to manage a product catalog efficiently.
- Create – Add new products with name, description, and price.
- Read – View all products in a sortable, responsive table.
- Update – Edit existing product information.
- Delete – Remove products from the database with confirmation.
- Security – Basic protection against XSS and SQL injection.
- Responsive Design – Clean, mobile-friendly interface using CSS.
The application is organized into the following files and directories:
index.php– Main page displaying the list of products.create.php– Form to add a new product.read.php– Detailed view of a single product.update.php– Form to edit an existing product.delete.php– Handles product deletion.config/database.php– Database connection class.includes/functions.php– CoreProductclass with all CRUD methods.assets/css/style.css– Stylesheet for the user interface.assets/js/script.js– JavaScript for client‑side validation and interactivity.database.sql– SQL dump to create the database and sample data.
- PHP 7.4 or higher
- MySQL 5.7 or higher
- A web server (Apache / Nginx)
- A modern web browser
- Create a MySQL database (e.g.,
crud_app). - Import the provided
database.sqlfile to create theproductstable and insert sample data.
Edit config/database.php and update the database credentials (host, db_name, username, password) to match your environment.
Copy all project files into your web server’s document root (e.g., htdocs/crud-app/).
Open your browser and navigate to http://localhost/crud-app/. You should see the product list.
- View Products – The homepage (
index.php) lists all products in a table with ID, name, description preview, price, creation date, and action buttons. - Add a Product – Click the “Add New Product” button, fill in the form, and submit.
- View Details – Click the “View” button next to any product to see its full description and details.
- Edit a Product – Click “Edit” to modify the product’s information.
- Delete a Product – Click “Delete” and confirm the action in the pop‑up dialog.
- SQL Injection Prevention – All database queries use PDO prepared statements.
- XSS Protection – User input is sanitized with
htmlspecialchars()before being displayed. - Input Validation – Basic client‑side (HTML5) and server‑side validation ensure data integrity.
- Session Management – PHP sessions are used for flash messages (e.g., success/error notifications).
| Problem | Possible Solution |
|---|---|
| Database connection error | Verify MySQL is running and credentials in database.php are correct. Ensure the database crud_app exists. |
| 404 Page Not Found | Check that all files are in the correct directories and that paths in require statements are accurate. |
| 500 Internal Server Error | Enable PHP error reporting to see the exact error. Check PHP error logs. Ensure PHP version is 7.4+. |
| Blank page on form submission | Ensure that error reporting is enabled and check for syntax errors in your PHP files. |
- Google Chrome (latest)
- Mozilla Firefox (latest)
- Apple Safari (latest)
- Microsoft Edge (latest)
- Opera (latest)
Contributions are welcome! Feel free to fork this project and submit pull requests for improvements or bug fixes.
This project is open‑source and available under the MIT License.
If you encounter any issues:
- Review the troubleshooting section above.
- Check your PHP error logs.
- Ensure all prerequisites are correctly installed.
Happy Coding! 🚀