Delete data from MySQL table using PHP.

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments
  • Post last modified:October 5, 2020
  • Reading time:2 min(s) read

In this tutorial, we’ll learn how to Delete data from MySQL table using PHP. In the previous tutorial, we learned how to insert data into the database using PHP, How to select data from a database using PHP and MySQL, And Update/Edit data into MySQL using PHP.

Now, it’s time to learn how to delete data from MySQL table using PHP. The SQL “DELETE” statement is used to delete data from MySQL Table. First of all, we have to create a (.) dot PHP file i.e, delete.php. After that, visiting inside the view page clicking on the delete button we need to link up with delete.php and fetch the row id from the MySQL table.

<a href="delete.php?delete=<?php echo $row['id'];?>" class="btn btn-danger">Delete</a>
Delete data from MySQL table using PHP

To delete selected data from MySQL, the simple syntax is –

DELETE FROM test WHERE id=$delete  
 Here is the complete code for Delete data from MySQL table using PHP, MySQL, Bootstrap 4
<?php
$con=mysqli_connect('localhost','root','','php');
if (isset($_GET['delete'])) {
	$delete=$_GET['delete'];

	$query="DELETE FROM test WHERE id=$delete ";
	$del=$con->query($query);
	if ($del) {
		header('location:view.php');
	}else{
		echo "SOMETHING WENT WRONG";
	}

}

?>

Leave a Reply