This article mainly introduces the comment reply in php in detail. Delete function has a certain reference value. Interested friends can refer to
Simple comment reply Delete function, the specific content is as follows
1. Database
Create two tables, one is the pinglun table; the other is the huifu table

The effect is as follows:

The code is as follows:
1. Main page main.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" >
<title>无标题文档</title>
<h1>朋友圈</h1>
<p>内容:</p>
<p>今天很嗨</p>
<p><img src= "../picture/timg.jpg" width= "300" height= "200" ></p><br>
<form action= "mainchuli.php" method= "post" >
<input type= "text" hidden= "hidden" value= "zhangsan" name= "zhangsan" > <!--因为没有权限,这里给了一个默认值-->
<textarea name= "content" ></textarea><input type= "submit" value= "评论" ><!--评论显示的地方--><!--单击评论提交内容进处理页面-->
</form>
<!--?php
require "DBDA.class.php" ;
$db = new DBDA();
$sql = "select * from Pinglun" ;
$arr = $db --->query( $sql ,1);
foreach ( $arr as $v )
{
echo "
<p style= "color:blue" >{ $v [1]} { $v [3]}</p>
<p style= "color:blue" >{ $v [2]}</p>
<form action= "delchuli.php?id={$v[0]}" method= "post" >
<input type= "submit" value= "删除" >
</form>
<form action= "huifuchuli.php?id={$v[0]}" method= "post" >
<textarea name= "Comment" ></textarea><input type= "submit" value= "回复" >
</form>
";
$dc = new DBDA();
$sql1 = "select * from huifu where jieshouid ={$v[0]}" ;
$arr1 = $dc ->query( $sql1 ,1);
foreach ( $arr1 as $k )
{
echo "<p>{ $k [2]} { $k [3]}</p>
<p>{ $k [4]}</p>
";
}
}
?>
|
Copy after login
2. Comment processing page pinglunchuli.php
1 2 3 4 5 6 7 8 9 10 | <?php
$zhangsan = $_POST [ "zhangsan" ];
$content = $_POST [ "content" ];
$time = date ( "Y-m-d H:i:s" );
require "DBDA.class.php" ;
$db = new DBDA();
$sql = "insert into Pinglun values('','{$zhangsan}','{$content}','{$time}')" ;
$db ->query( $sql );
header( "location:main.php" );
|
Copy after login
3. Reply processing page huifuchuli.php
1 2 3 4 5 6 7 8 9 10 11 | <!--?php
$id = $_GET [ "id" ];
$Comment = $_POST [ "Comment" ];
$me = "me" ;
$Times = date ( "Y-m-d H:i:s" );
require "DBDA.class.php" ;
$db = new DBDA();
$sql = "insert into huifu values('','{$id}', '{$me}','{$Times}','{$Comment}')" ;
$db --->query( $sql );
header( "location:main.php" );
|
Copy after login
4. Delete processing page delchuli.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php
$id = $_GET [ "id" ];
require "DBDA.class.php" ;
$db = new DBDA();
$sql = "delete from Pinglun where id='{$id}'" ;
if ( $db ->query( $sql ))
{
header( "location:main.php" );
}
else
{
echo "删除失败!" ;
}
|
Copy after login
The above is the detailed content of PHP example-php implements comment reply and delete function. For more information, please follow other related articles on the PHP Chinese website!