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
12Soni  Kumari35
14Ankit Kumar30
16Neelam  Kumari25
18Raj Kumar27

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 :

IDNAMEAGE
12Soni Kumari35
14Ankit Kumar30
16Neelam Kuamri25

Leave a Reply