Project 2: PHP CRUD Blog System

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

ColumnPurpose
idUnique post ID
titleBlog post title
contentBlog content
created_atPost 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)

  1. Create post (Insert)
  2. Display all posts (Read)
  3. Edit post (Update)
  4. Delete post (Delete)

Related Tutorials

Leave a Reply

Your email address will not be published. Required fields are marked *