Home Php PHP MySQL Delete
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

PHP MySQL Delete

Advertisement
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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 17, 2009

Ask Questions?    Discuss: PHP MySQL Delete  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
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
DMCA.com