Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:10:28+00:00 2026-06-13T20:10:28+00:00

My friends and I are creating a petition board and i’m adding a like/dislike

  • 0

My friends and I are creating a petition board and i’m adding a like/dislike function to it. I intend to make it such that only users can like/dislike it. Problem is, I do not know how to ensure that the users do not spam the button multiple times and how to register which user has liked/disliked which topic. Below is my code so far.

EDIT: Thanks I am creating the likes/dislikes table right now. But now I have to compare the users with the database to see if they have previously liked a comment. I know I have to use WHERE (to check both likes and dislikes table) but i am not sure how to combine it with IF.

<?php
include connect.php

if (isset($_POST['like']) || isset($_POST['dislike'])) 
{
    if($_SESSION['signed_in']){
        if (isset($_POST['like'])) {
            $sql="UPDATE 
                    topics
                SET
                    likes=likes+1,
                WHERE
                    id=topic_id";

            echo "You liked it";
        }

        elseif (isset($_POST['dislike'])) {
            $sql="UPDATE 
                    topics
                SET
                    dislikes=dislikes+1,
                WHERE
                    id=topic_id";

            echo "You disliked it";
        }
    }
    else{
        echo 'Please log in.'
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:10:29+00:00Added an answer on June 13, 2026 at 8:10 pm

    You should have a table of “likes” with the following columns.

    “article_id”, “user_id”, the primary key should contain both columns

    Every time a user likes an article, INSERT INTO likes VALUES($article_id, $user_id);
    It will fail if someones Likes twice, thanks to the primary key.

    Every time a user dislikes, DELETE FROM likes WHERE article_id = $article_id AND user_id = $user_id. That will allow the user to like again if he wants.

    To get the number of Likes for an article, run a SELECT COUNT(*) as nb_of_likes FROM likes WHERE article_id = $article_id instead of storing the number in the article table.

    Makes sense ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a db schema that involves users that can be friends, and I
I'm actually creating websites for fun and some of my friends told me that
friends. I have a 'make'-like style file needed to be parsed. The grammar is
I'm creating a library that includes both Clojure and Java code, and would like
Is there a better/easier way to find mutual friends between users than creating a
I have 2 divs that I am creating from an array: $.each(data, function(i,item) {
I have several apps that I work on and like to distribute to friends
I would like to make it able for my users to add each other
how do i make that in the creating screen of content type i will
I am Creating A facebook that Retrieves 10 Random friends.But I need some code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.