Quality business correspondence.
Delete a record
Remember we display the records to edit and selected the record we want.
We are going to use the same method to delete a record. There are two files involved to delete a record.
First file (toDelete.php) is to view all the records
and the second file (deleteComment.php)
is to delete selected record.
Code to list records from feeds
toDelete.php
<head>
<title>Display feeds for edit</title>
</head>
<body >
<?php
include("connect.inc");
print "<table width='100%' border='1'>";
$query="SELECT * FROM feed";
$result=mysql_query($query);
$num=mysql_numrows($result);
print "<tr><td align='center'>Edit</td><td align='center'>Name</td></tr>";
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
$comments=stripslashes(mysql_result($result,$i,"comments"));
$id=mysql_result($result,$i,"user_id");
print "<tr><td><a href='deleteComment.php?id=$id'>Delete</a></td><td>$name</td></tr>";
$i++;
}
mysql_close($dbh);
print "</table>";
?>
</body>
</html>
The purpose of this file to view records and select one.
Selected record is deleted through deleteComment.php file.
deleteComment.php
<?php
include("connect.inc");
$msg="";
if(isset($_REQUEST['id']))
{
$id=$_REQUEST['id'];
}
else
{
$id=NULL;
$msg =$msg." Wrong access. ID is null. <a href='toDelete.php'>Try again</a><br>";
}
if($id!=null)
{
$query = "DELETE FROM feed WHERE user_id='$id'";
mysql_query($query);
$msg =$msg." Selected feed was successfully deleted... <a href='toDelete.php'>Delete another</a>";
}
print "<font color='red'>$msg</font>";
?>
No explanations were given since we are dealing with SQL statements combined with php, to learn more about
SQL, go to our SQL section.
View the example demo
Update Data
Virtual Includes