How to DELETE Data Into MySQL Database Using PHP ?
The DELETE statement is used to delete records from a table.
you can delete records from a table using the SQL DELETE statement. It is typically used in conjugation with the WHERE clause to delete only those records that matches specific criteria or condition.
Syntax :
DELETE FROM table_name
WHERE some_column = some_value ;
Implementation of the Delete Query :
Let us consider the following table ‘ Data ‘ with three columns ‘ ID ‘, ‘ Name ‘ and ‘ Age ‘.
ID | NAME | AGE |
12 | Soni Kumari | 35 |
14 | Ankit Kumar | 30 |
16 | Neelam Kumari | 25 |
18 | Raj Kumar | 27 |
DELETE Query using Procedural Method :
<?php
$link= mysqli_connect("localhost", "root", "", "company");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql= "DELETE FROM employee WHERE ID=18"
;if(mysqli_query($link, $sql)){
echo "Record was deleted successfully.";
}
else
{
echo "ERROR: Could not able to execute $sql. "
. mysqli_error($link);
}
mysqli_close($link);
?>
Output :
Table update :
ID | NAME | AGE |
12 | Soni Kumari | 35 |
14 | Ankit Kumar | 30 |
16 | Neelam Kuamri | 25 |