Home Php PHP MySQL Delete



PHP MySQL Delete
Posted on: December 17, 2009 at 12:00 AM
In SQL, sometimes we need to delete unwanted records from the table.

PHP MySQL Delete:

     

In SQL, sometimes we need to delete unwanted records from the table. SQL provides delete statement for this purpose. delete command can be used for delete one or more than one record at a time.

General format of the delete command is given as below:

delete from <table name>

where <condition>

 

Example:

<?php

$db=mysql_connect("localhost","root","");

if(!$db)

{

die("Can not Connect".mysql_error());

}

mysql_select_db("roseindia",$db);

echo "<br/> Before deletion :<br/>";

$result=mysql_query("select * from student");

while($row=mysql_fetch_array($result))

{

echo $row['e_id']." ".$row['age']."<br/>";

}

mysql_query("delete from student where e_id='emp02'");

echo"<br/>After Deletion a record:<br/>";

$result=mysql_query("select * from student");

while($row=mysql_fetch_array($result))

{

echo $row['e_id']." ".$row['age']."<br/>";

}

?>

Output:

Before deletion :
emp01 26
emp02 27
emp05 26
emp_05 28
After Deletion a record:
emp01 26
emp05 26
emp_05 28

Related Tags for PHP MySQL Delete:


More Tutorials from this section

Ask Questions?    Discuss: PHP MySQL Delete  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.