Part 1 – Project Overview & Database Design
In this project, we will build a simple blog system using PHP and MySQL where users can:
- Create blog posts
- View all posts
- Edit existing posts
- Delete posts
This project will help you understand CRUD operations in a real-world scenario.
What You Will Build
By the end of this project, you will have:
- Admin panel for managing posts
- Blog post creation form
- Post listing page
- Edit & delete functionality
- Secure database interaction
Concepts Used in This Project
- PHP Forms (POST)
- MySQL Database
- mysqli (Prepared Statements)
- Loops
- Sessions (optional)
- Basic security practices
Database Design
Step 1: Create Database
Using phpMyAdmin, create a database:
crud_blog
Step 2: Create posts Table
CREATE TABLE posts (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
content TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Column Explanation
| Column | Purpose |
|---|---|
| id | Unique post ID |
| title | Blog post title |
| content | Blog content |
| created_at | Post date |
Project Folder Structure
Create a folder like this:
crud-blog/
│
├── db.php
├── index.php
├── create.php
├── edit.php
├── delete.php
Simple and easy to understand.
Database Connection (db.php)
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "crud_blog";
$conn = mysqli_connect($host, $user, $pass, $db);
if (!$conn) {
die("Database connection failed");
}
?>
How This Project Will Be Built (Flow)
- Create post (Insert)
- Display all posts (Read)
- Edit post (Update)
- Delete post (Delete)
