Skip to content

SketchyXenon/php-crud-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Simple PHP CRUD Application

📋 Overview

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.

🚀 Features

  • 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.

📁 Project Structure

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 – Core Product class 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.

🔧 Installation Guide

Prerequisites

  • PHP 7.4 or higher
  • MySQL 5.7 or higher
  • A web server (Apache / Nginx)
  • A modern web browser

Step 1: Database Setup

  1. Create a MySQL database (e.g., crud_app).
  2. Import the provided database.sql file to create the products table and insert sample data.

Step 2: Configure Database Connection

Edit config/database.php and update the database credentials (host, db_name, username, password) to match your environment.

Step 3: Place Files on Your Server

Copy all project files into your web server’s document root (e.g., htdocs/crud-app/).

Step 4: Access the Application

Open your browser and navigate to http://localhost/crud-app/. You should see the product list.

🎯 Usage

  • 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.

🔒 Security Features

  • 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).

🐛 Troubleshooting

Common Issues and Solutions

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.

📱 Browser Support

  • Google Chrome (latest)
  • Mozilla Firefox (latest)
  • Apple Safari (latest)
  • Microsoft Edge (latest)
  • Opera (latest)

🤝 Contributing

Contributions are welcome! Feel free to fork this project and submit pull requests for improvements or bug fixes.

📄 License

This project is open‑source and available under the MIT License.

🆘 Support

If you encounter any issues:

  • Review the troubleshooting section above.
  • Check your PHP error logs.
  • Ensure all prerequisites are correctly installed.

Happy Coding! 🚀

About

CRUD Application purely developed using PHP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors