CRUD operation using PHP and MySQLi

0

- Advertisement -

In this tutorial, we will learn how to create CRUD operation using PHP and MySQLi.

CRUD Stands for create, read, update and delete record in the database.

Files includes in this tutorials

  • phpcrud.sql: Contain the database table structure.
  • dbconnection.php: Used for database connection.
  • index.php: Used to fetch the record from database.
  • read.php: Used to fetch the record of particular user.
  • edit.php: Used to edit the record.
  • insert.php: Used to insert the new record.

Step 1– Create a database

Open browser type http://localhost/phpmyadmin, create a database named ‘phpcrud’. After creating database run the SQL script or import the SQL file.

MySQL Table tblusers structure

Step 2– Create a database connection file(dbconnection.php)

Step 3– Create a HTML form for data insertion

Step 4– Now write PHP Code for data insertion and put this code at the top of the insert.php file.

Once the user filled all the data and click on the submit button then data will be saved in the database using the below code:

Step 5– Read / Fetch the record from the database(index.php)

In this step we will fetch all data from the database.

Step 6–Read / Fetch the particular record (read.php)

create read.php file. For fetching a record we have to get the row id of that record and store in $vid. We access the $_GET[‘viewid’] variable to do it.
Code for gets a record based on the given id. 

Step 7 –Edit/ Update the particular record (edit.php)

Step 7.1 Fetch the data in the HTML Form.

create edit.php file. For updating a record we have to get the row id of that record and store in $eid. We access the $_GET[‘editid’] variable to do it.
Code for gets a record based on the given id. Through this way, we can get data autofill-data in HTML Form.

Step 7.1 Code for update the particular record. Put this code on the top of the edit.php

Step 8 – Code for data deletion from the database

Download Source Code (CRUD operation using PHP and MySQLi)
Size: 9.31 KB
Version: V 1

- Advertisement -

Leave A Reply

Your email address will not be published.