Delete records using PHP MySQL Statement
We use the DELETE statement to delete records in a table.
Syntax
DELETE FROM table_name
WHERE some_column = some_value
Please note the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!
To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.
Example
Look at the following “student” table:
FirstName LastName Age
Garry Kristen 25
Jhon Don 22
The following example deletes all the records in the “student” table where LastName=’Kristen’:
<?php
con = mysql_connect(“localhost”,”username”,”password”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“schooldatabase”, $con);
mysql_query(“DELETE FROM student WHERE LastName=’Kristen’”);
mysql_close($con);
?>
After the deletion, the table will look like this:
| FirstName | LastName | Age |
|---|---|---|
| Jhon | Don | 22 |
Follow @phpzag

I enjoy what you guys are up too. Such clever function and exposure! Keep up the really excellent works guys I’ve incorporated you guys to my own blogroll.