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 6111629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:39:09+00:00 2026-05-23T14:39:09+00:00

I’m making a simple voter that takes either a like vote or dislike vote.

  • 0

I’m making a simple voter that takes either a “like” vote or “dislike” vote. Then, I count the total number of likes and dislikes and output the total numbers. I figured out how to put in the votes using Jquery Ajax, but the number of votes do not update after I put in a vote. I would like to update the $numlike and $numdislike variables using Jquery Ajax.

Here is the PHP script pertaining to the output:

$like = mysql_query("SELECT * FROM voter WHERE likes = 1 ");
$numlike = 0;
while($row = mysql_fetch_assoc($like)){ 
    $numlike++;
}

$dislike = mysql_query("SELECT * FROM voter WHERE likes = 0 ");
$numdislike = 0;
while($row = mysql_fetch_assoc($dislike)){  
    $numdislike++;
}

echo "$numlike like";
echo "<br>";
echo "$numdislike dislike";

UPDATE:
Jquery Ajax for uploading vote

<script>
$(document).ready(function(){
    $("#voter").submit(function() {

    var like     = $('#like').attr('value');
   var dislike   = $('#dislike').attr('value');

        $.ajax({
            type: "POST",
            url: "vote.php",
            data: "like=" + like +"& dislike="+ dislike,   
            success: submitFinished
            });

            function submitFinished( response ) {
  response = $.trim( response );

  if ( response == "success" ) {
        jAlert("Thanks for voting!", "Thank you!");
        }

    return false;
    });
});
</script>

<form id="voter" method="post">
<input type='image' name='like' id='like' value='like' src='like.png'/>
<input type='image' name='dislike' id='dislike' value='dislike' src='dislike.png'/>
</form>

vote.php:

if ($_POST['like'])
{
    $likeqry  = "INSERT INTO test VALUES('','1')";
    mysql_query($likeqry) or die(mysql_error());
    echo "success";
}

if ($_POST['dislike'])
{
    $dislikeqry  = "INSERT INTO test VALUES('','0')";
    mysql_query($dislikeqry) or die(mysql_error());
    echo "success";
}
  • 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-05-23T14:39:09+00:00Added an answer on May 23, 2026 at 2:39 pm

    If you want to change current like or dislike number after clicking it you must return result instead of printing it ! return json result and echo this and change div innerHTML to see new result !

    ............
    ............
    ............
    $dislike = mysql_query("SELECT * FROM voter WHERE likes = 0 ");
    $numdislike = 0;
    while($row = mysql_fetch_assoc($dislike)){  
        $numdislike++;
    }
    
    echo json_encode( array( $numlike, $numdislike ) ) ;
    exit();
    

    Now in your html code :

           $.ajax({
                type: "POST",
                url: "vote.php",
                context:$(this)
                data: "like=" + like +"& dislike="+ dislike,   
                success: submitFinished(data)
                });
    
                function submitFinished( response ) {
      response = $.parseJSON( response );
      //Now change number of like and dilike but i don't know where are shown in your html
      $('#like').attr('value',response[0]);
      $('#dislike').attr('value',response[1]);
      return false;
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.