Im working with a database to create a like system. All was working fine until I added a function which adds a like each time a person likes a post. It is a mysql_query where I set the old likes to the new likes plus one.
It looks like this:
mysql_query("UPDATE `news` SET `post_likes` = `post_likes` + 1 WHERE `post_id` = $post_id");
This is the whole function:
function add_like($post_id){
$post_id = (int)$post_id;
mysql_query("UPDATE `news` SET `post_likes` = `post_likes` + 1 WHERE `post_id` = $post_id");
mysql_query("INSERT INTO `likes` (`id` , `post_id`) VALUES (".$_SESSION['id'].", $post_id)");
}
The plus one is what I suspect is going wrong. When I print out the post_likes it prints out the correct value.
It is adding 9 to each value instead of 1.
Any Ideas why this could be happening? I may be over looking something so simple.
Thanks all!