2017-12-27 313 views
0

這是一場真正的鬥爭。我一直試圖調試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 
} 
?> 
+0

那麼它在做什麼錯? – RiggsFolly

+0

_Small point_你需要和'exit;'後面的'header()'作爲頭不停止執行當前腳本,它只是向瀏覽器發送一個頭文件 – RiggsFolly

+0

新增了我的錯誤。 – mechanicarts

回答

0

ORDER BY id DESC不工作,因爲我的數據庫字段被稱爲 「com_postid」。
$timestamp = $row['timestamp']不起作用,因爲我的db字段被稱爲「com_timestamp」。