1

此评论框应该将评论发送到我的数据库,然后将其显示在评论框下,但是当我提交评论时没有任何反应。它只是显示在数据库中。谢谢你 。

<?php
require ('connects.php');
$comment=$_POST['comment'];
$submit=$_POST ['submit'];


if ($submit) { $insert=mysql_query ("INSERT INTO comment (comment) VALUES    ('$comment')" ) ;


} 


?>


<html>
<head><title>Comment Box | HelperTuts</title></head>
<body>
<form action="comment-box.php" method="POST">

<label>Comment:  </label><br />
<textarea name="comment" cols="25" rows="7"></textarea><br /><br /><br />
<input type="submit" name="submit" value="Comment" /><br />

</form>
<hr width="1100px" size="5px" />

<?php

$getquery="SELECT comment FROM comment ORDER id DESC " ;
while($rows=mysql_fetch_assoc($getquery))
{

$id=$rows['id'] ;
$comment=$rows['comment'];
echo $comment["comment"] ;


} 

?>


</body>
</html>
4

2 回答 2

2

你没有运行查询。您刚刚构建了 SQL 并将其保留为字符串。此外,它是 ORDER BY,而不是 ORDER:

<?php

$getquery = "SELECT id, comment FROM comment ORDER BY id DESC ";
$result = mysql_query($getquery) or trigger_error(mysql_error());
while($rows=mysql_fetch_assoc($result))
{

    $id=$rows['id'] ;
    $comment=$rows['comment'];
    echo $comment["comment"] ;


} 

?>
于 2013-05-05T08:13:12.117 回答
1

让我试一试:)

<?php
$mysqli=Mysqli("127.0.0.1","root","DATABASE_PASSWORD","DATABASE_NAME");

$comment=$_POST['comment'];
$comment=$mysqli->real_escape_string($comment);
$submit=$_POST ['submit'];

if ($submit) {
    $insert=$mysqli->query("INSERT INTO `comment`(`comment`) VALUES('".$comment."')");
} 
?>
<!DOCTYPE html>
<html>
<head><title>Comment Box | HelperTuts</title></head>
<body>
<form action="comment-box.php" method="post">
<label>Comment:  </label><br />
<textarea name="comment" cols="25" rows="7"></textarea><br /><br /><br />
<input type="submit" name="submit" value="Comment" /><br />
</form>
<hr width="1100px" size="5px" />
<?php
$getquery="SELECT `comment` FROM `comment` ORDER BY `id` DESC";
$result=$mysqli->query($getquery);
while($rows=$result->fetch_assoc($getquery)) {
    $id=$rows['id'] ;
    $comment=$rows['comment'];
    echo $comment["comment"] ;
} 
?>
</body>
</html>
于 2013-05-05T08:20:24.020 回答