[an error occurred while processing this directive]

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

                         

[an error occurred while processing this directive]