I'm trying to do an update query. The part that is throwing me off is having the variables in the prepare part of this. I'm trying to grab the existing $cid and $tid that is associated with the page I am on.
$cid = category id
$tid= topic id
I commented out the bind paramater because I already have the variables defined on the page.
I then get this error:
Fatal error: Call to a member function execute() on a non-object in
How can I make this prepared statement work and make this an object so it runs?
$stmt3 = $con->prepare("UPDATE forum_topics SET topic_views='".$new_views."' WHERE category_id'".$cid."' AND id='".$tid."' LIMIT 1");
//$stmt3->bind_param("ii", $cid, $tid);
$stmt3->execute();
$stmt3->store_result();
$row3 = $stmt3->fetch();
} else {
Additional code...
$old_views = $row['topic_views'];
$new_views = $old_views + 1;
//$stmt3 = $con->prepare("UPDATE forum_topics SET topic_views='".$new_views."' WHERE category_id'".$cid."' AND id='".$tid."' LIMIT 1");
$stmt3 = $con->prepare("UPDATE forum_topics SET `topic_views`=? WHERE `category_id`=? AND `id`=? LIMIT 1");
$stmt3->bind_param("iii", $new_views, $cid, $tid);
$stmt3->execute();
//$stmt3->store_result();
$row3 = $stmt3->fetch();
} else {
echo "<p>This topic does not exist.</p>";
}