Home Backend Development PHP Tutorial Detailed explanation of examples of implementing comment reply and delete function in PHP

Detailed explanation of examples of implementing comment reply and delete function in PHP

May 22, 2018 pm 12:05 PM
php delete Function

This article mainly introduces the comment reply and delete function in PHP in detail. It has certain reference value. Interested friends can refer to

Simple comment reply and 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

<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]}"; //查询回复表中的id和传过去的id是不是一样的
          $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

<?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

<!--?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");
Copy after login

4. Delete the processing page 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 "删除失败!";
}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

Detailed explanation of how PHP implements the comment reply and delete function

php example-php implementationComment reply delete function

ajax implements comment function without refreshing

The above is the detailed content of Detailed explanation of examples of implementing comment reply and delete function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles