The below method is returning an error after I added && in_array($itemID, $userItemIDS)
to the if statement.
Fatal error: Call to a member function bind_param() on a non-object
/**
* Deactivate item.
*
* @param (int) $itemID - Variable representing an item's id.
*/
public function deactivate($itemID) {
//get user item ids
$userItemIDS = $this->helperClass->userItemIDS();
if( $q = $this->db->mysqli->prepare("UPDATE items SET active = 0 WHERE id = ?") && in_array($itemID, $userItemIDS) )
{
$q->bind_param("i", $itemID);
$q->execute();
$q->close();
return true;
}
return false;
}
I would separate out the call to
prepare
and first check to make sure that the call succeeded:This will also make your code easier to read and maintain.