PHPWeb Development Projects

PHP Crud Operation Step by Step | Create Read Update Delete Operation in PHP.

Hello Everyone in this artcle we will learn about how to make php crud operation step by step. So if you like this article then find more interested topics on the searchbar. Guys here you can get the source code free related all articles in this website.

Requirement For PHP Crud

First of all you should have knowledge of html and css which you can learn from w3school and at the same time you can also see by running the code there. Then after that you should have knowledge of basic PHP like what is PHP and how do we use it and what is it used for in the website.

After that you have to download a code editor in which we can write code. In this article, we have used Visual Studio Code, if you want to download Visual Studio Editor, after that we will need a server because we can run PHP only on the server, so we will need a local server. to run. So in this article we have used xampp server which is running php, so i will recommend you to use xampp server only for php.

HTML Code.

Friends, now we will know how to make the structure of our project, so let’s know. All you have to do is open the Visual Studio Editor. After that we have to go to bootstrap website and from there we have to code the starter template then come to our visual studio code and create a folder which we will name PHP Crud Operation and we have to put that folder in our xampp’s folder Going to fund the folder of htdocs in it, then this folder has to be fasted in the folder of htdocs.

Then we have to create a file inside this folder, whose name we will save by keeping add.php.

<div class="container">
        <div class="row mt-4">
            <div class="col-md-6 m-auto">
                <a class="btn btn-primary mb-4" href="view.php">View All</a>
                <form method="POST">
                    <h2>Create Student</h2>
                    <input type="text" name="name" placeholder="Student Name" autocomplete="off"><br><br>
                    <input type="text" name="subject" placeholder="Subject" autocomplete="off"><br><br>
                    <input type="text" name="course" placeholder="Course" autocomplete="off"><br><br>
                    <button class="btn btn-success" type="submit" name="submit">ADD NEW</button>


CSS Code.

Friends, now we will know how to design this PHP Crud Operation project, so let’s know. All you have to do is create css file for styling. After that link this style.css file in the html header then you can use this file for design project.

form {
            padding: 30px;
            background-color: #fff;
            border-radius: 10px;
            text-align: center;

        form h2 {
            margin-bottom: 20px;

        form input {
            width: 100%;
            border: none;
            outline: none;
            border-bottom: 1px solid black;

PHP Code.

Data Base Connection file.

$conn = mysqli_connect('localhost','root','','cruddatabse');

    echo "not connected";


php code file.

//Create PHP Code..

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $course = $_POST['course'];

    $insrtQ = "INSERT INTO `crudtable`(`name`, `subject`, `class`) VALUES ('$name','$subject','$course')";

    $addData = mysqli_query($conn, $insrtQ);
    if ($addData) {
        echo '<script>alert("User Added Successfully");</script>';
        echo '<script>window.location.href="view.php";</script>';
    } else {
        echo "not submit";

//View PHP Code..

$getData = "SELECT * FROM `crudtable`";

                            $getQuery = mysqli_query($conn, $getData);

                            while ($fetchData = mysqli_fetch_array($getQuery)){

//Update PHP Code..
$getId = $_GET['id'];
$selectQ = "SELECT * FROM `crudtable` where id='".$getId."'";
$q = mysqli_query($conn,$selectQ);
$fetData = mysqli_fetch_array($q);

if (isset($_POST['update'])) {
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $course = $_POST['course'];
$updateQ = "UPDATE `crudtable` SET `name`='$name',`subject`='$subject',`class`='$course' where id='".$getId."'";

$editQ = mysqli_query($conn,$updateQ);
    echo '<script>alert("Updated Successfully");</script>';
    echo '<script>window.location.href="view.php";</script>';
    echo "something wen't wrong";

//Delete PHP Code..

$getId = $_GET['id'];
$deleteQ = "DELETE FROM `crudtable` WHERE id = '".$getId."'";
$delq = mysqli_query($conn,$deleteQ);

    echo '<script>alert("User Deleted Successfully");</script>';
    echo '<script>window.location.href="view.php";</script>';
    echo "not delete";

Watch Video Related this Article

PHP Crud Operation

Related Articles

Leave a Reply

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

Back to top button