这个评论框应该将评论发送到我的数据库,然后在评论框下显示它,但是当我提交评论时没有任何反应。它只是显示在数据库中。谢谢。
<?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>
最佳答案
您没有运行查询。您刚刚构建了 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"] ;
}
?>
关于php - 简单的评论框 php 和 mysql 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16382620/