📌 What You'll Build:
• A record listing table
• A form to add new entries
• Edit & delete functionality
• Database connectivity with MySQL
• Bootstrap UI with alerts and modals
🧱 Prerequisites:
• PHP 7.4+
• MySQL/MariaDB
• A local server (XAMPP, WAMP, or MAMP)
• Basic HTML/CSS/PHP knowledge
🔧 Step 1: Set Up Your Project Structure
/crud-php-bootstrap/
├── config.php
├── index.php
├── create.php
├── update.php
├── delete.php
└── assets/
└── bootstrap.min.css
⚙️ Step 2: Create Your Database Table
CREATE DATABASE crud_app;
USE crud_app;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
📄 Step 3: config.php – DB Connection
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "crud_app";
$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
📋 Step 4: index.php – Show All Records
<?php include 'config.php'; ?>
<!DOCTYPE html>
<html>
<head>
<title>PHP CRUD</title>
<link rel="stylesheet" href="assets/bootstrap.min.css">
</head>
<body class="container mt-5">
<h2>User List <a href="create.php" class="btn btn-primary float-end">+ Add New</a></h2>
<table class="table table-bordered mt-3">
<thead><tr><th>ID</th><th>Name</th><th>Email</th><th>Actions</th></tr></thead>
<tbody>
<?php
$result = $conn->query("SELECT * FROM users");
while ($row = $result->fetch_assoc()):
?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= $row['name'] ?></td>
<td><?= $row['email'] ?></td>
<td>
<a href="update.php?id=<?= $row['id'] ?>" class="btn btn-warning btn-sm">Edit</a>
<a href="delete.php?id=<?= $row['id'] ?>" onclick="return confirm('Delete?')" class="btn btn-danger btn-sm">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</body>
</html>
🆕 Step 5: create.php – Add New User
<?php include 'config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$conn->query("INSERT INTO users (name, email) VALUES ('$name', '$email')");
header("Location: index.php");
}
?>
<form method="POST" class="container mt-5">
<h2>Add User</h2>
<input name="name" class="form-control mb-2" placeholder="Name">
<input name="email" class="form-control mb-2" placeholder="Email">
<button class="btn btn-success">Save</button>
</form>
✏️ Step 6: update.php – Edit User
<?php
include 'config.php';
$id = $_GET['id'];
$user = $conn->query("SELECT * FROM users WHERE id=$id")->fetch_assoc();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$conn->query("UPDATE users SET name='$name', email='$email' WHERE id=$id");
header("Location: index.php");
}
?>
<form method="POST" class="container mt-5">
<h2>Edit User</h2>
<input name="name" value="<?= $user['name'] ?>" class="form-control mb-2">
<input name="email" value="<?= $user['email'] ?>" class="form-control mb-2">
<button class="btn btn-warning">Update</button>
</form>
🗑️ Step 7: delete.php
<?php
include 'config.php';
$id = $_GET['id'];
$conn->query("DELETE FROM users WHERE id=$id");
header("Location: index.php");
?>
✅ Final Output :
• Fully responsive UI using Bootstrap
• Add/Edit/Delete records
• Simple PHP-only structure, no framework
• Great starter project