I have done this successfully. Here is how I did it:
You have a table in the database called "likes" with the username, postid (as well as the date, id, if you want too)
Each post / blog / article must have its own identifier.
When someone likes a post / blog / article, you take the id of the post / article / article and the username that you liked , and check the likes of the database to see if it exists. If it already exists, you delete it. If it does not exist, you add similar.
For example, with AJAX, thatโs how I did it specifically:
I have a blog post with id 6.
Jonathan likes this post.
These 2 variables are sent via the mail form and wait for a response, she likes the logical check of the database to see if this record already exists in the table tables (username, postid) ('Jonathan', 6 ), if the answer is 1 (or true ), then I update the div number for the like button from any value that was originally, and add 1. If the answer is 0 (or false), then I take the original value in the counter I like and delete 1.
source share