PHP (Core & Framework)

How to modify your data using mysql

In this tutorial you will learn the following things :-

  • Deleting your record
  • Edit your record

How to Delete a particular record

To delete a particular record from your data you need to pass a sql query :-

$sql= “delete from myrecords where item_id=”.$_GET[‘id’];”

GET is used to request data from a specified resource.

Now using the function ‘mysqli_query($conn,$sql)’

across the row, also pass connection file and sql query as its arguments.

If this function is executed then your data is deleted successfully !


Header is used to take you to the page where all your records are present this done once the record is deleted !!

Records before deletion
Records after deletion


$sql="delete from myrecords where item_id=".$_GET['id'];

	echo "<br> Record Deleted Successfully !";

How to Edit your record 

To edit your records you need to pass sql UPDATE query. The UPDATE statement is used to update existing records in a table.

$sql=”update myrecords set  title=’$ti’,startdate=’$sd’,enddate=’$ed’,postdate=’$pd’ where item_id=$id”;

This query runs to add new details to the existing ones.

Once you click the edit button a new form is opened to edit the required details.

TITLE:<input type=”text” name=”title” value=”<?php echo $row[‘title’];?>”><br>

As you all must be knowing that how to create a form here you see that in input tag we have specified the value of each one. This is done because the user would like to see the previous data and would be able to edit the required data according to his need.

<form name=f1 method=post action=”>

<input type=”hidden” name=”item_id” value=”<?php echo $_GET[‘id’];?>”>

Here type is hidden because The <input type=”hidden”> defines a hidden input field.

A hidden field let web developers include data that cannot be seen or modified by users when a form is submitted.

A hidden field often stores what database record that needs to be updated when the form is submitted.

Rest function are described in previous tutorials.

Records Before Editing

Records after editing




 $sql="update myrecords set  title='$ti',startdate='$sd',enddate='$ed',postdate='$pd' where item_id=$id";

 	echo "Updated Successfully !!!";
 	echo "There was some error!!";
	$sql="select * from myrecords where item_id=".$_GET['id'];
	echo $sql;
	<form name=f1 method=post action=''>
		<input type="hidden" name="item_id" value="<?php echo $_GET['id'];?>">
		TITLE:<input type="text" name="title" value="<?php echo $row['title'];?>"><br>
		START DATE:<input type="Date" name="s"value="<?php echo $row['startdate'];?>"><br>
		END DATE:<input type="Date" name="e"value="<?php echo $row['enddate'];?>"><br>
		POST DATE:<input type="Date" name="p"value="<?php echo $row['postdate'];?>"><br>
		<input type="submit" name="submit" value="Update">


Posted by: Rhythm Arya

Comment here