user3346088
user3346088

Reputation: 109

Fatal error: Call to a member function bind_param() on a non-object

$stmt = $db->prepare("SELECT post_id,content,date,category_id,lp_title,lp_image,lp_canonicalUrl,lp_url,lp_desc,lp_iframe,lp_iframe_id,img_src
    FROM post_items INNER JOIN user ON post_items.user_id = user.user_id INNER JOIN photo_upload ON post_items.post_id = photo_upload.post_id
     WHERE post_items.user_id = ? AND post_items.post_id = photo_upload.post_id order by post_items.post_id desc LIMIT ?,?");


$stmt->bind_param('iii', $userid, $itemStart, $itemEnd);

I have 3 table here: user, post_items and photo_upload. before I implement the photo_upload, everything is working.

I got an error saying

Fatal error: Call to a member function bind_param() on a non-object in

Upvotes: 0

Views: 402

Answers (1)

h2ooooooo
h2ooooooo

Reputation: 39540

The documentation of mysqli::prepare mentions that it returns:

mysqli_prepare() returns a statement object or FALSE if an error occurred.

Try the following:

$stmt = $db->prepare("SELECT post_id,content,date,category_id,lp_title,lp_image,lp_canonicalUrl,lp_url,lp_desc,lp_iframe,lp_iframe_id,img_src
    FROM post_items INNER JOIN user ON post_items.user_id = user.user_id INNER JOIN photo_upload ON post_items.post_id = photo_upload.post_id
     WHERE post_items.user_id = ? AND post_items.post_id = photo_upload.post_id order by post_items.post_id desc LIMIT ?,?");

if ($stmt !== false) {
    $stmt->bind_param('iii', $userid, $itemStart, $itemEnd);
} else {
    print_r( $db->error );
}

Upvotes: 1

Related Questions