如何将评论与postid与该邮件的帖子绑定?

这是一场真正的斗争。我一直试图调试1小时的更好的一部分,但我找不到任何解决方案。我正在制作一个与博客帖子关联的评论系统。当您发表评论时,您将返回到相同的帖子。帖子页面根据postid动态填充。评论是使用相同的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

}

?>

回答:

ORDER BY id DESC不工作,因为我的数据库字段被称为 “com_postid”。
$timestamp = $row['timestamp']不起作用,因为我的db字段被称为“com_timestamp”。

以上是 如何将评论与postid与该邮件的帖子绑定? 的全部内容, 来源链接: utcz.com/qa/265684.html

回到顶部