php - Why do I get Call to a member function bind_param() on a non-object...? -
i making game class , have added commenting system go it. wanting add ability report comment.
i have added column in comments table called report_active , idea set 1 when active (meaning has been reported) , 0 when isn't. list in admincp of comments active report on them.
i have made file called report_comment.php intend used run queries redirect page.
this report_comment.phppage:
<?php require_once('db_connect.php'); require_once('security.php'); if (isset($_get['id'])) { $report_active = 1; $id = $_get['id']; $select = $db->query("select * comments id = ?"); $select->bind_param('i', $id); if ($select->execute()) { if ($select->num_rows) { // run update query $update = $db->query("update comments set report_active = ? id = ?"); $update->bind_param('ii', $report_active, $id); if ($update->execute()) { header('location: comments.php'); die(); } } } } ?> what doing wrong? error returned with:
fatal error: call member function bind_param() on non-object
$select = $db->query("select * comments id = ?"); ^^^^^---execute query you want
$stmt = $db->prepare("select * comment id = ?"); ^^^^^^^---note diff instead. plus, should checking failure, e.g.
if ($stmt === false) { die("prepare failed error: " . $db->errorinfo); } or similar particular db library.
Comments
Post a Comment