I have a problem with this code for make a hit counter per user profile on PDO (MYSQL), on page loads not update and not show the counter, only text "Visits:", the value remains at "0".
$id = $profile_data['username'];
$statement = $db->query("SELECT `visits` FROM `users` WHERE id='$id'");
$record = $statement->fetchAll();
if(sizeof($record) != 0)
{
$counter = $record[0]['counter']++;
$db->exec("UPDATE `users` SET visits='$counter' WHERE id='$id'");
echo "Visits: " .$counter;
}
else
{
$db->exec("INSERT INTO `users` (id, visits) VALUES ('$id', 1)");
echo "Visits: 1";
}
Since you pulling the fields
visits
from the database, you need to change:to: