0

I am getting the "Fatal error: call to a member function fetch_array() on boolean in c" error when trying to execute my php script. The code in question is here:

    <?php while ($row = $posts->fetch_array()) :?>
      <div class="blog-post">
        <h2 class="blog-post-title"><?php echo $row['title'];?></h2>
        <p class="blog-post-meta"> ON <?php echo formatDate($row['date']);?> BY <a href="#"><?php echo $row['author'];?></a></p>

        <img style = "float:left; margin-right:20px;margin-botton:10px;" src = 'images/<?php echo $row['image'];?>' width = "200" height = "200">
        <p style="text-align:justify;"><?php echo substr($row['content'],0,300);?></p>
        <a id = "readmore" href = "single_post.php? id=<?php echo $row['id'];?>">Read More</a>

      </div><!-- /.blog-post -->

      <?php endwhile;?>

PHP code right before this is:

<?php

include "libs/config.php";
include "libs/database.php"; 
include "functions.php";


$id = ''; 
if( isset( $_GET['id'])) {
     $id = $_GET['id']; 
} 
$db = new database();
$query = "SELECT * FROM posts WHERE category_id = '$id'";
$posts = $db->select($query);

?>

My error is in this line:

<?php while ($row = $posts->fetch_array()) :?>

I tried a lot to resolve this problem but i couldn't. Can anyone help me out?

Yubraj Rai
  • 33
  • 1
  • 13
  • Is `database()` is a custom made database wrapper? If so you need to show us the code of the `select()` method, my guess is that a query function like `mysqli_query` fails and returns false – dimlucas Jun 21 '16 at 07:50
  • http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12769983#12769983 – deceze Jun 21 '16 at 07:53
  • You're vulnerable to **SQL injection!** – deceze Jun 21 '16 at 07:54

0 Answers0