PHP for simple comment and reply function and delete information

Source: Internet
Author: User

Let's first look at the function

Above the black is the comment below the red font is reply

and see how it's going to come true.

1. Post a comment

<form action= "pinglunchili.php" method= "POST" ><textarea name= "content" ></textarea><div> <input type= "Submit" value= "comments"/></div></form>

This is the text field of the comment

Post-comment content to be stored in the database to process

Because this is just to implement a simple comment and reply so there is no login permission so the name inside is added.

<?php$yonghu= "Caocao"; $content =$_post["content"; $time =  date ("y-m-d h:i:s"); require "DBDA.class.php"; $db = New Dbda (); $sql = "INSERT into Pinglun values (', ' {$yonghu} ', ' {$content} ', ' {$time} ')", if ($db->query ($sql, 0)) { Header ("location:pinglun.php");} Else{echo "you entered the error! ";}

2. Reply function Here is a comment followed by a reply

<?phprequire "DBDA.class.php"; $db =new Dbda (); $sql = "SELECT * from Pinglun"; $arr = $db->query ($sql); foreach ($arr As $v) {echo "<div>{$v [0]}</div>  <div>{$v [1]}</div>          <div>{$v [2]}</div >  <div>{$v [3]}</div>  <form action= ' huifuchuli.php?id={$v [0]} ' method= ' post ' >  <input type= ' text ' name= ' Comment '/>                  <input type= ' submit ' value= ' reply '/></form> '; $dc = new Dbda ();  $sql 1= "select * from Huifu where jieshouid={$v [0]}"; $arr 1= $dc->query ($sql 1); foreach ($arr 1 as $f) {echo "<div Style= ' color:red ' >{$f [0]}</div>  <div style= ' color:red ' >{$f [2]}</div>  <div style= ' color:red ' >{$f [3]}</div>  <div style= ' color:red ' >{$f [4]}</div> ";}}? >

The content of the comment and the content of the reply are traversed to show the effect in the diagram.

This allows you to implement a comment followed by a reply

3. Then delete the message

is to add a Delete button to the front of the reply.

<form action= ' shanchuchuli.php?id={$v [0]} ' method= ' post ' >  <input type= ' submit ' value= ' delete '/></ form>  <form action= ' huifuchuli.php?id={$v [0]} ' method= ' post ' >  <input type= ' text ' name= ' Comment '/>          <input type= ' submit ' value= ' reply '/></form> ';

Working with pages

That's it. The delete button in the diagram

Let's try the effect:

  

This will delete the information.

Plus the login and permissions feature will be updated later.

  

PHP for simple comment and reply function and delete information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.