I'm adding a view counter to my website. In the code, I check if there's an IP with the id of the post.
for example when post id is 26, and there's no IP with id 26 in my IP table, it should return 0 but it returns 1 instead.
$userIp = $_SERVER['REMOTE_ADDR'];
$checkIp = $db->prepare("SELECT user_ip FROM user_ip WHERE word_id = '$idToShow'");
$checkIp->execute();
//This happens
if (count($checkIp) > 0) {
echo count($checkIp);
echo " ". $idToShow;
}
//instead of this
else {
$insertIP = $db->prepare("INSERT INTO user_ip (user_ip, word_id) values('$userIp', '$idToShow')");
$insertIP->execute();
$updateView = $db->prepare("UPDATE words set views = views + 1 WHERE id = '$idToShow'");
$updateView->execute();
}
$checkIpyour PDOStatement object or similar? At least it isn't a result set...