PHP MySQL DELETE Statement Example

PHP MySQL DELETE Statement Example


Posted in : PHP Posted on : February 3, 2011 at 5:57 PM Comments : [ 0 ]

In this example you can learn how to delete records in the database table using mysql DELETE statement in the php application.

PHP MySQL DELETE Statement Example:

In this example you can learn how to delete records in the database table using mysql DELETE statement in the php application.

Syntax:

DELETE FROM table_name WHERE column_name = column_value

Example:

<?php
$connection = mysql_connect("localhost","root","root");

if (!$connection) {
die('PHP Mysql database connection could not connect : ' . mysql_error());
}
else{ 
$db_name = "php_mysql";

mysql_select_db($db_name, $connection);
$sql = "delete from user where user_id=1;";
$records = mysql_query($sql, $connection); 
echo "Delete record successfully.";
}
mysql_close($connection); 
?> 

Output:

Before running this example the database table records is:

After running this example the browser output is:

Delete record successfully.

And the database table records is:

Download Example Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics