Delete the data in the database
The DELETE FROM statement is used to delete records from the database table.
Syntax DELETE FROM table_name WHERE column_name = some_value
Note: SQL is not case sensitive. DELETE FROM equivalent to delete from.
In order for PHP to execute the above statement, we must use mysql_query (function. This function is used to send queries and commands to the SQL connection.
example
Earlier, we created a table named "Person" in this tutorial. It looks something like this:
FirstName LastName Age Peter Griffin 35 Glenn Quagmire 33
The following example deletes all the records of LastName = 'Griffin' in the "Person" table:
<? php $ con = mysql_connect ("localhost", "peter", "abc123"); if ($ con) {die ('Could not connect:'. mysql_error ());} mysql_select_db ("my_db", $ mysql_query ("DELETE FROM Person WHERE LastName = 'Griffin'"); mysql_close ($ con);?>
After this deletion, the table looks like this:
FirstName LastName Age Glenn Quagmire 33