Skip to main content
phpMyAdmin Guide
CHAPTER 18 Beginner

Build a PHP MySQL CRUD Application | Step-by-Step Guide

Updated: May 16, 2026
15 min read

# CHAPTER 18

Building CRUD Applications with phpMyAdmin and PHP

1. Introduction

We have arrived at the synthesis of all your skills. You know how to visually architect tables in phpMyAdmin, and you know how to write secure connection scripts in PHP. Now, it is time to build a complete, end-to-end software application. We are going to conceptualize a Student Management System that allows a user to perform all four foundational database operations (CRUD: Create, Read, Update, Delete) entirely through a web browser.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Architect the backend schema using phpMyAdmin.
  • Implement the 'Create' operation (HTML Form to MySQL).
  • Implement the 'Read' operation (MySQL to HTML Table).
  • Implement the 'Update' operation (Edit forms).
  • Implement the 'Delete' operation (URL parameters).

3. Phase 1: Database Setup (phpMyAdmin)

Before writing any PHP, we must prepare the database using the tools we learned in Chapters 4 & 5.
  1. 1. Open phpMyAdmin.
  1. 2. Create a database named schooldb.
  1. 3. Create a table named students with 4 columns:
  • id (INT, Primary Key, Auto Increment)
  • firstname (VARCHAR 100)
  • last_name (VARCHAR 100)
  • email (VARCHAR 150)
  1. 4. Use the Insert tab in phpMyAdmin to add 2 fake students so we have data to test with.

4. Phase 2: The 'Read' Operation (index.php)

The homepage of our application should display a list of all students. Create index.php:
php
1234567891011121314151617181920212223242526
<?php require &#039;db_connect.php'; ?>
<html>
<body>
    <h2>Student Roster</h2>
    <a href="create.php">Add New Student</a>
    <table border="1">
        <tr><th>ID</th><th>Name</th><th>Email</th><th>Actions</th></tr>
        <?php
        $sql = "SELECT * FROM students";
        $result = mysqli_query($conn, $sql);
        while($row = mysqli_fetch_assoc($result)) {
            echo "<tr>";
            echo "<td>" . $row[&#039;id'] . "</td>";
            echo "<td>" . $row[&#039;first_name'] . " " . $row['last_name'] . "</td>";
            echo "<td>" . $row[&#039;email'] . "</td>";
            // Action links for Update and Delete
            echo "<td>
                    <a href=&#039;edit.php?id=".$row['id']."'>Edit</a> | 
                    <a href=&#039;delete.php?id=".$row['id']."'>Delete</a>
                  </td>";
            echo "</tr>";
        }
        ?>
    </table>
</body>
</html>

5. Phase 3: The 'Create' Operation (create.php)

We need a form to add new students to the database. Create create.php:
php
123456789101112131415161718
<?php
require &#039;db_connect.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Secure Prepared Statement for Insertion
    $stmt = $conn->prepare("INSERT INTO students (first_name, last_name, email) VALUES (?, ?, ?)");
    $stmt->bind_param("sss", $_POST[&#039;fname'], $_POST['lname'], $_POST['email']);
    $stmt->execute();
    header("Location: index.php"); // Redirect back to homepage
}
?>
<!-- HTML Form -->
<form method="POST">
    First Name: <input type="text" name="fname"><br>
    Last Name: <input type="text" name="lname"><br>
    Email: <input type="email" name="email"><br>
    <button type="submit">Save Student</button>
</form>

6. Phase 4: The 'Delete' Operation (delete.php)

If a user clicks the "Delete" link on the homepage, it sends the student's ID to delete.php via the URL. Create delete.php:
php
1234567891011121314
<?php
require &#039;db_connect.php';

// Check if an ID was passed in the URL
if (isset($_GET[&#039;id'])) {
    $student_id = $_GET[&#039;id'];
    
    // Secure Prepared Statement for Deletion
    $stmt = $conn->prepare("DELETE FROM students WHERE id = ?");
    $stmt->bind_param("i", $student_id); // "i" means Integer
    $stmt->execute();
}
header("Location: index.php");
?>

7. Phase 5: The 'Update' Operation (edit.php)

The hardest part. We must Read the data, put it into a form, and then Update it. Create edit.php:
php
12345678910111213141516171819202122232425
<?php
require &#039;db_connect.php';
$id = $_GET[&#039;id'];

// 1. Fetch current data to fill the form
$stmt = $conn->prepare("SELECT * FROM students WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$student = $stmt->get_result()->fetch_assoc();

// 2. Handle the Form Submission to Update the database
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $update_stmt = $conn->prepare("UPDATE students SET first_name=?, last_name=?, email=? WHERE id=?");
    $update_stmt->bind_param("sssi", $_POST[&#039;fname'], $_POST['lname'], $_POST['email'], $id);
    $update_stmt->execute();
    header("Location: index.php");
}
?>
<!-- HTML Form pre-filled with data -->
<form method="POST">
    First Name: <input type="text" name="fname" value="<?php echo $student[&#039;first_name']; ?>"><br>
    Last Name: <input type="text" name="lname" value="<?php echo $student[&#039;last_name']; ?>"><br>
    Email: <input type="email" name="email" value="<?php echo $student[&#039;email']; ?>"><br>
    <button type="submit">Update Student</button>
</form>

8. Mini Project: Verify via phpMyAdmin

The ultimate test of a Full Stack developer is using the database dashboard to verify the frontend code.
  1. 1. Go to your PHP website index.php. Click "Add New Student". Fill out the form and submit.
  1. 2. Open phpMyAdmin.
  1. 3. Select schooldb -> students.
  1. 4. Click the Browse tab.
  1. 5. If the new student appears in the visual grid, your PHP CRUD application is functioning flawlessly!

9. Common Mistakes

  • Trusting User Input: Beginners often forget to validate data. What if a user submits a blank first name? What if the email doesn't have an @ symbol? While Prepared Statements protect against SQL Injection, they do not protect against bad data. You must write PHP code to validate the input *before* sending it to MySQL.

10. Best Practices

  • Soft Deletes: In enterprise applications, you almost never use the DELETE command. If you delete an employee, their historical payroll data is orphaned. Instead, you use a Soft Delete. You add an isactive boolean column to the table. When a user clicks "Delete," you actually run an UPDATE students SET isactive = 0. Then, your index.php simply queries SELECT * FROM students WHERE isactive = 1.

11. Exercises

  1. 1. In a standard CRUD application, which HTTP method (GET or POST) is strictly required when submitting HTML forms to create or update data?
  1. 2. What database management concept involves changing a column value to "inactive" rather than physically executing a DELETE query?

12. Database Challenges

You built a CRUD application. The index.php page successfully displays 100 students. However, a user clicks the "Edit" link for Student #5, and the edit.php form is completely blank instead of being pre-filled with Student #5's data. Explain the conceptual architectural flaw in your code. *(Answer: The edit.php page failed to execute a SELECT query based on the id provided in the URL parameter. It must query the database for that specific ID and echo the result into the HTML value="" attributes of the input fields before the user can see them).*

13. MCQ Quiz with Answers

Question 1

In a typical PHP/MySQL CRUD application architecture, what is the required sequence of database operations necessary to properly facilitate an "Edit/Update" workflow for a user?

Question 2

An enterprise application opts to utilize "Soft Deletes" rather than physical DELETE FROM SQL commands. How is this architectural strategy structurally implemented at the database schema level in phpMyAdmin?

14. Interview Questions

  • Q: Walk me through the complete architectural flow of a "Create" operation. Start from the HTML form submission, explain the PHP validation and Prepared Statement execution, and describe how you would verify the insertion using phpMyAdmin.
  • Q: Explain the concept of a "Soft Delete" versus a "Hard Delete". Why do enterprise financial and relational systems strictly forbid Hard Deletes?

15. FAQs

Q: I built the CRUD app, but it looks ugly. How do I make it look like a real web app? A: PHP only handles the backend logic! To make it look beautiful, you must add CSS. Most developers use a framework like Bootstrap or TailwindCSS to style the HTML <table> and <form> elements to look modern and professional.

16. Summary

You are no longer just a database administrator; you are a Software Engineer. By architecting the backend schema in phpMyAdmin and writing the foundational CRUD logic in PHP, you have built a complete, interactive web application capable of managing dynamic data over the internet.

17. Next Chapter Recommendation

You have mastered the mechanics of the dashboard and the code. Now, it is time to look at the big picture. How do professionals actually spend their day? In Chapter 19: Real-World Database Administration Workflows, we will step into the shoes of an Enterprise DBA and execute daily maintenance, optimization, and auditing tasks.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·