Delete Data From MySQL Using PHP – Tutorial

For deleting data from MySQL the DELETE statement is used. We can delete data from specific column or all column of a table.

For delete selected column data from database the SQL query is

DELETE FROM table_name WHERE some_column=column_value;
The SQL query for delete all the column data from a table
DELETE FROM table_name;
DELETE * FROM table_name;

In the tutorial we delete the details data from MySQL database.

In this example we used 2 file for retrieve data

  • database.php– To connecting database.
  • delete.php– For getting data from database with delete option
  • delete-process.php– For remove data from database or from your table


 die('Could not Connect My Sql:' .mysql_error());


include_once 'database.php';
$result = mysqli_query($conn,"SELECT * FROM details");

<!DOCTYPE html>
<title>Delete user details</title>
	<td>First Name</td>
	<td>Last Name</td>
	<td>Email id</td>
	while($row = mysqli_fetch_array($result)) {
	<tr class="<?php if(isset($classname)) echo $classname;?>">
	<td><?php echo $row["id"]; ?></td>
	<td><?php echo $row["firstname"]; ?></td>
	<td><?php echo $row["lastname"]; ?></td>
	<td><?php echo $row["city"]; ?></td>
	<td><?php echo $row["email"]; ?></td>
	<td><a href="delete-process.php?id=<?php echo $row["id"]; ?>">Delete</a></td>


include_once 'database.php';
$sql = "DELETE FROM details WHERE id='" . $_GET["id"] . "'";
if (mysqli_query($conn, $sql)) {
    echo "Record deleted successfully";
} else {
    echo "Error deleting record: " . mysqli_error($conn);

Leave a Reply

Your email address will not be published.