Hello guyz, if you are searching for tutorial which show inserting, deleting updating and searching data in your MySQL database through PHP script, then you are in the right article. In this tutorial article, we are gonna talk about it. This is the most basic operation in any programming language and this rule applies to PHP too. Without knowing this basic step, you can not develop either small or big project using PHP. So lets start.

First of all you need to have any server application installed in your PC. Without server application you can not execute any php file because PHP is server side scripting language. So, to make your PC as a server you need to install server application. I am using Wamp Server but you can use any server application software.

Download Wampserver: http://www.wampserver.com/en/


1. After installing this application, Start your wampserver, then open your localhost, for this open up your any browsing software and type localhost or in the address bar. Then new page will appear then scroll down and find phpmyadmin and click on that. Then you will be able to see the login page. Login in by entering username and password (Default username is root and password is empty). And then click on new and create one database having any name you want and the click ok, then create table having any number of field you want but i am using four field in this case and click on go. After that, you need to insert the field name like: Roll No, Name, Address etc. and then select the length as well as data type as your requirement and then click on save. You can watch the video for this designing part, you may understand better in video. Make sure that make any one filed primary key, generally Roll No is set as PK because of unique identification than other field.

2. Open your any text editing software, i am using Dreamweaver CC, and then define site and testing server for your Dreamweaver cc, see this article.

3. After completing this task, write the following piece of code and save it in .php extension.

<!doctype html>
$servername = "localhost";


//connect to mysql database
$conn =mysqli_connect($servername,$username,$password,$dbname);
}catch(MySQLi_Sql_Exception $ex){
echo("error in connecting");
//get data from the form
function getData()
$data = array();
return $data;
$info = getData();
$search_query="SELECT * FROM idusnew WHERE Rollno = '$info[0]'";
$search_result=mysqli_query($conn, $search_query);
while($rows = mysqli_fetch_array($search_result))
$Rollno = $rows['Rollno'];
$fname = $rows['fname'];
$lname = $rows['lname'];
$address = $rows['address'];
$email = $rows['email'];

echo("no data are available");
} else{
echo("result error");

$info = getData();
$insert_query="INSERT INTO `idusnew`(`fname`, `lname`, `address`, `email`) VALUES ('$info[1]','$info[2]','$info[3]','$info[4]')";
$insert_result=mysqli_query($conn, $insert_query);
echo("data inserted successfully");

echo("data are not inserted");
}catch(Exception $ex){
echo("error inserted".$ex->getMessage());
$info = getData();
$delete_query = "DELETE FROM `idusnew` WHERE Rollno = '$info[0]'";
$delete_result = mysqli_query($conn, $delete_query);
echo("data deleted");
echo("data not deleted");
}catch(Exception $ex){
echo("error in delete".$ex->getMessage());
$info = getData();
$update_query="UPDATE `idusnew` SET `fname`='$info[1]',lname='$info[2]',address='$info[3]',email='$info[4]' WHERE Rollno = '$info[0]'";
$update_result=mysqli_query($conn, $update_query);
echo("data updated");
echo("data not updated");
}catch(Exception $ex){
echo("error in update".$ex->getMessage());

<meta charset="utf-8">
<title>Untitled Document</title>

<form method ="post" action="idusnew.php">
<input type="number" name="Rollno" placeholder="Roll No" value="<?php echo($Rollno);?>"><br><br>
<input type="text" name="fname" placeholder="First Name" value="<?php echo($fname);?>"><br><br>
<input type="text" name="lname" placeholder="Last Name" value="<?php echo($lname);?>"><br><br>
<input type="text" name="address" placeholder="Address" value="<?php echo($address);?>"><br><br>
<input type="text" name="email" placeholder="example@example.com" value="<?php echo($email);?>"><br><br>
<input type="submit" name="insert" value="Add">
<input type="submit" name="delete" value="Delete">
<input type="submit" name="update" value="Update">
<input type="submit" name="search" value="Find">


4. Open this .php file in any browser you want. 🙂

That’s it guyz. If you have any confusion, you can watch the video.





Please enter your comment!
Please enter your name here