Reputation: 105
First thing to say is I am somewhat new to the whole SQL prepared statment thing. Here is my issue, when I try and count the number of times a user has rated a post I am not getting a response, instead I get an odd error. Any help would be appreciated.
$query = "SELECT COUNT(*) FROM `rate` WHERE `userID`=? AND `postID`=?";
if($stmt = $connection->prepare($query)){
$stmt->bind_param("ii", $id, $post_id);
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
echo $count;
} else {
echo $connection->error;
}
And the error given by the echo $connection->error is: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
Upvotes: 0
Views: 84
Reputation: 1251
As stated by @Fred-ii ->
`COUNT(*) AS totalcount` then bind result on $totalcount
it's also important to have error_reporting(E_ALL); ini_set('display_errors', 1);
on top of pages in pre-prod
Upvotes: 3