Home Ask Login Register

Developers Planet

Your answer is one click away!

fraser_28 February 2016

How can I limit each user to just one like per page?

I have a liking system, a bit like what facebook have. However, users can like pages as many times as possible.. How can I limit it to just one for each user like per page? The code I have is:

    session_start() ;
    $conn = mysqli_connect("","","","");
    $p_id = $_GET['post_id'];
    $result = mysqli_query($conn, "SELECT * FROM forum WHERE post_id = $p_id");
    $row = mysqli_fetch_assoc($result);
    mysqli_query($conn, "UPDATE forum SET likes=likes+1 WHERE post_id = '$p_id'") ;
    header("Location: forum.php?id=".$row['post_id']);


recycler February 2016

You have to track the user. Make a table with userid and postid

Post Status

Asked in February 2016
Viewed 3,915 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life