December 30, 2013 9:21 am

How to create Like & Unlike System in PHP MySQL and jQuery

I have received many requests from my users to write an article on like and dislike with PHP and MySQL so today I am going to give a tutorial on like and unlike in PHP and MySQLi its very use full for your websites to get users review on pages on stories any many more.


Improved Version: Create Like & Unlike System in PHP MySQL and jQuery [Improved]

Database Details:
database name => phpgang
table name => like
Database file run in your MySQL to create database and add data in table.

Edit this file as per your database credentials.


Contains PHP code to update table records and show the current number in the file, in this file we used cookie to skip invalid likes and un-likes.

Include db.php file and first run query in like to get number of like and un-like for a particular id here I have added static id you can make it for your dynamic system.


Contain styles of like and unlike buttons to make them look nicer on your UI.


Contain jQuery methods to handle like and unlike counts and disable and enable icons.

In this js we have captured current like count and add one in that and update value of button val = val+1;

I hope you like this simple script to add like and un-like feature in your websites please update me with your feedback in comments below and we also provide you code to download and a demo to check it.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • Innocent Prince

    Could you please make of this tutorial for WordPress ?

  • Awesome, how about creating only one button (just like in facebook) and if user is not a liker, show “Like” else “Unlike” along with total likers 😉

    • huzoorbux

      if you don’t like something then what will you do that’s why we have 2 options if you like you like else dislike..

      • I would first query for current status (liked or not) and on this basis, display Like or Unlike. It’ll be good too. Isn’t it?

      • payal


  • Huserman

    I think it’s not right way, because user may remove COOKIE and “Like” many times 🙂

  • adarwash

    Hi, I have got my sort of working, when i click like it say already liked, and the counter stay the same until page is refreshed and i can click it as many time as i what, anyone got any idea why it doing this, thanks in advance

  • Vo Thanh Toan

    Good, thanks!

  • Brobi Wan Knobi

    Cannot download the code even if i sucessfully registered to the feed! 🙁

    BTW whats the ‘op’ in this “$_POST[‘op’]) ” ;

  • love arman

    is this love??

    • septiyo

      Why you Upload something Sucks and out of topic?

  • Pro PHP

    this code is sucks and is not secure
    whoever wrote this is a total newbs

  • Max John

    I am already a suscriber but i can not download anymore: it says i am not a suscriber and when i try to subscribe it says I am a subscriber . Hence i can not download. I like your website you are doing a great Job

  • Max John

    We want one that we can independently use on our website, not just a code

  • doesn’t work fatso and doesn’t even have a submit button.



  • Thank you very much.

  • Firdous Farooq Bhat

    How it will work when you are not giving POST METHOD in the html code?

  • Meryam Hil

    Hello ^^”,
    First i want to thank you for th efforts. Secondly, i’m a brand new person in learning php code ! i created the whole files needed but i didn’t get any result except two blank buttons ! :/ i hope u can help me thank you in advanced

  • hh


  • Randy J. Tomlinson

    demo doesn’t work.

  • asdasdasd


  • asdasdasd


  • asdasdasd


  • asdasdasd


  • asdasdasd


  • dd


  • dd


    • Arbiyantoro

      how to kae reply like this shit