• php-简单的评论回复删除功能


    简单的评论回复删除功能

    一、数据库

    建立两张表,一是pinglun表;二是huifu表

     效果如下:

    代码如下:

    1.主页面 main.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <h1>朋友圈</h1>
    <div>内容:</div>
    <div>今天很嗨</div>
    <div><img src="../picture/timg.jpg" width="300" height="200" /></div><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" <div style='color:blue'>{$v[1]} {$v[3]}</div> <div style='color:blue'>{$v[2]}</div> <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]}"; //查询回复表中的id和传过去的id是不是一样的 $arr1 = $dc->query($sql1,1); foreach($arr1 as $k) { echo "<div>{$k[2]} {$k[3]}</div> <div>{$k[4]}</div> "; } } ?> </body> </html>

     2.评论处理页面 pinglunchuli.php

    <?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");
    

     3.回复处理页面 huifuchuli.php

    <?php
    $id = $_GET["id"]; //将点击回复的评论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");
    

     4.删除处理页面 delchuli.php

    <?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 "删除失败!";
    }
    
  • 相关阅读:
    java实现万年历
    java中关于Calendar
    java中各种类型的输入输出
    java(向上向下转型)
    MyEclipse还原默认窗口
    Hibernate映射问题之OneToOne【自己整理】
    Neither BindingResult nor plain target object for bean
    剑宗与气宗
    分治算法
    spring处理线程并发
  • 原文地址:https://www.cnblogs.com/zhaohui123/p/6891430.html
Copyright © 2020-2023  润新知