如何向发布评论的用户显示删除和编辑链接?就像在 Facebook 中一样,只有发表评论的人才能编辑或删除评论。下面是我的“显示评论”、“显示删除”和“编辑评论”PHP 文件:
<?php
include_once("includes/settings.php");
connect();
$result=mysql_query("SELECT * FROM comments ORDER BY id DESC");
echo "<table width='80%' border=0>";
echo "<tr bgcolor='#CCCCCC'>";
echo "<td>Name</td>";
echo "<td>Comments</td>";;
echo "</tr>";
while($res=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$res['Name']."</td>";
echo "<td>".$res['Comments']."</td>";
echo "<td><a href=\"edit_comment.php?id=$res[id]\">Edit</a> | <a href=\"includes/delete.php?id=$res[id]\">Delete</a></td>";
}
echo "</table>";
?>
下面是edit.php
<?php
error_reporting(0);
include_once("settings.php");
connect();
if(isset($_POST['submit'])) {
$id = $_POST['id'];
$Comments=$_POST['Comments'];
if(empty($Comments)) {
echo "<font color='red'>Comments field is empty.</font><br/>";
}
else {
$result=mysql_query("UPDATE comments SET Comments='$Comments' WHERE id=$id");
echo "Your comments has been edited you will be redirected to the members area page automatically or <a href='../index_ma.php'>click here to go back</a>";
header('refresh: 3; url=../index_ma.php');
}
}
?>
<?php
$id = $_GET['id'];
$result=mysql_query("select * from comments where id='$id'");
while($res=mysql_fetch_array($result))
{
$Comments = $res['Comments'];
}
?>
下面是delete.php
<?php
include_once("settings.php");
connect();
$id = $_GET['id'];
$result=mysql_query("DELETE FROM comments where id=$id");
echo "Your comments has been deleted you will be redirected to the members area page automatically or <a href='../index_ma.php'>click here to go back</a>";
header('refresh: 3; url=../index_ma.php');
?>