I am receiving this message "Fatal error: Call to a member function bind_param() on a non-object in C:\xampp\htdocs\pcms\includes\blog.php on line 65" for using the following code in a script I am working on.
As a bit of a PHP novice (coding to learn) I would like to know if it is not possible to use a prepared statement inside a while loop from another prepared statement.
If anybody could point out where I am going wrong/other ways of going about this (still using prepared statements) I would be very grateful.
// Load the blog data from the database and display a row for each blog post
$result = $dbc->prepare("SELECT id, title, post, date, time, blog, b_id, name, comment FROM blog ORDER BY id DESC LIMIT $start_blog , $blog_per_page");
$result->execute();
$result->bind_result($id, $title, $post, $date, $time, $blog, $b_id, $name, $comment);
<?php
while ($row = $result->fetch()) {
if ($blog == 1) {
// Count the number of comments for the current blog post
$count = $dbc->prepare("SELECT COUNT( b_id ) FROM blog WHERE b_id = ?");
$count->bind_param('s', $id); <-- Line 65
$count->execute();
$count->store_result();
$no_comments=$count->num_rows;
?>
<div style="margin-top:15px; margin-bottom:15px; border:1px solid #444444; padding:7px;">
<div style="float:left; width:50%;"><b><?php echo $title; ?></b></div>
<div style="float:right; text-align:right; width:50%;"><?php echo $date; ?> at <?php echo $time; ?></div>
<div style="width:100%; padding-top:25px;"><?php echo nl2br(substr($post, 0, 100));?><?php if (strlen($post) >= 100); { echo '...'; } ?></div>
<div style="width:100%; padding-top:25px;"><?php echo "<a href=\"$page-p-$id.html\" title=\"View comments for $title\"><i>Comments ($no_comments)</i></a> "; ?></div>
</div>
<?php
}
}
?>
Many thanks Jim