PHP MySQL Delete

In SQL, sometimes we need to delete unwanted records from the table.


 
Ads

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

Advertisements

Ads
Share on Google+Share on Google+

PHP MySQL Delete

Posted on: December 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: PHP MySQL Delete  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
isaac nyaata
September 12, 2012
coding skills

i like coding using php with c++. i see ur codes are just fine. after implementing i'll b back

Ads

 

Ads