我尝试为网页创建评论,但现在我成功地使评论有效,但我的问题是如何添加回复并将其显示在它的相应评论下面。请尝试阅读其他代码示例,但我仍然可以弄明白。
的index.php
<!DOCTYPE html>
<html>
<head>
<title>
commenting system
</title>
</head>
<body>
<?php
include("db.php");
$date = date("d-F-Y" );
$nameErr = "";
$n = "at";
$sql = "SELECT * FROM client";
$result = mysqli_query($con,$sql);
while($row=mysqli_fetch_assoc($result))
{
echo $row['fname']."<br>";
echo $row['time']."<br>";
echo $row['comment']."<br>
<label name = 'reply' value = 'reply' style = 'background:blue;color:white;'><a href = ''>Reply</a></label><hr>
<style>#form{opacity:0;height:0;}</style>
<form action = 'cm.php' method = 'POST' id = 'form'>
<input type = 'text' name = 'fname' placeholder = 'Name'></input><br><br>
<input type = 'text' name = 'website' placeholder = 'website'><br><br>
<textarea type = 'text' name = 'scomment' rows = '6' col = '250' placeholder = 'comment here....'>
</textarea><br>
<button type = 'submit'>SUBMIT</button>
</form>";
}
?>
<form action = "cm.php" method = "POST">
<input type = "text" name = "fname" placeholder = "Name"></input><br><br>
<input type = "text" name = "website" placeholder = "website"><br><br>
<textarea type = "text" name = "scomment" rows = "6" col = "250" placeholder = "comment here....">
</textarea><br>
<button type = "submit">SUBMIT</button>
</form>
<label name = 'reply' value = 'reply' style = 'background:blue;color:white;border-radius:2px solid black;'>Reply</label>
</body>
</html>
cm.php
<?php
session_start();
include 'db.php';
$nameErr = "";
$date = date("d-F-Y" )." "." "." "." ".date( "H:i");
$fname = $_POST['fname'];
$website = $_POST['website'];
$scomment = $_POST['scomment'];
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(empty($_POST['fname'] && $_POST['scomment'])){
$nameErr = "Enter your name";
}else{
$sql = "INSERT INTO client (fname, website, comment,time) VALUES ('$fname', '$website', '$scomment','$date')";
$result = $con->query($sql);
}
}
header("Location:index.php");
?>