这是一场真正的斗争。我已经尝试在1小时的大部分时间内进行调试,但我无法找到任何解决方案。我正在建立一个与博客文章相关的评论系统。当您发表评论时,您将返回同一帖子。帖子页面基于postid动态填充。使用相同的postid添加注释,以便仅填充相关帖子。我查询评论的查询是错误的,但我不知道如何。
Warning
: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
in C:\xampp\htdocs\prog1\comments.php on line 31
代码:
<?php
require("connect.php");
$postid = $_GET['id'];
if(isset($_POST['postcomment'])){
$comment = $_POST['comment'];
$author = $_SESSION['username'];
$commentQuery = mysqli_query($conn, "INSERT INTO comments (com_content, com_timestamp, com_author, com_postid) VALUES ('$comment', now(), '$author', '$postid')");
if($commentQuery){
header('Location: postpage.php?id='.$postid);
}
}
?>
<div class="comments-separator">
</div>
<div class="flex-enable comments-wrapper flex-column">
<span class="comment-header">Comments</span>
<div class="comment-new-wrapper">
<form class="flex-enable flex-column" method="POST">
<textarea class="blog-input-text comment-entry" cols="40" rows="3" name="comment"></textarea>
<input class="comment-button small-white-subtitle" type="submit" name="postcomment" value="Post Comment">
</form>
</div>
</div>
<?php
$summonComm = "SELECT * FROM comments WHERE com_postid='".$postid."' ORDER BY id DESC";
$resultComm = mysqli_query($conn, $summonComm);
while ($row = mysqli_fetch_array($resultComm)){
$comment= $row['com_content'];
$timestamp= $row['timestamp'];
$author= $row['com_author'];
?>
<span class="blog-timestamp"><?php echo $timestamp; ?> • Written by <a href="<?php echo $author; ?>.php"><?php echo $author; ?></a></span>
<span class="blog-entry"><?php echo $comment; ?></span>
</div>
<?php
}
?>
答案 0 :(得分:0)
ORDER BY id DESC
不起作用,因为我的db字段名为“com_postid”
$timestamp = $row['timestamp']
不起作用,因为我的db字段名为“com_timestamp”。