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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:37:38+00:00 2026-05-25T16:37:38+00:00

The question is fairly simple. Whenever user clicks on like I want to use

  • 0

The question is fairly simple. Whenever user clicks on “like” I want to use javascript to update the mysql database through ajax. I have tried all means bit have found nothing helpful. I know I will also need a server side script but the ajax is the main issue.

Here is the counter code I set up.

 document.observe("dom:loaded", function()
{
  $("likeForumLink").onclick=processForumLike;

});


function processForumLike(event)
{

  var numberOfLikes=parseInt($("hiddenLikes").value); 

   numberOfLikes+=1;

  $("hiddenLikes").value=numberOfLikes+""; 

   this.innerHTML="You liked this"; 

  if(numberOfLikes==1)
  {
   $("numberOfLikes").innerHTML="("+numberOfLikes+" like)";

  }          
 else
 {
 $("numberOfLikes").innerHTML="("+numberOfLikes+" likes)";
 }

var likes=$("hiddenLikes").value;

new Ajax.Request("seeForum.php?id=$("subjectId").value", {

  method:'get', 
  parameters:{hiddenLikes:likes},      
  onSuccess: ????  //Don't know
  onComplete:???   //Don't know
  on Failure:????  //Don't know

 });
}

And then I can use my server side script as follows.
P.S. It lies in the same page "seeForum.php?subjectId=$("subjectId").value"

  <?php if(isset($_GET["hiddenLikes"]))
    {

     $updateQuery="UPDATE `subject table` SET  `likes`='".$_GET["hiddenLikes"]."' where `subjectId`='".$_REQUEST['subjectId']."' ";

     $result=mysql_query($updateQuery);

     checkConnect($result,"query of $updateQuery");


 ?> 

Please help. All my work has come to a halt.

  • 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-25T16:37:38+00:00Added an answer on May 25, 2026 at 4:37 pm

    First of all, you shouldn’t be using a GET request to update data, that should be a POST. And this:

    "seeForum.php?id=$("subjectId").value"
    

    doesn’t do what you probably think it does. What it does do is cause a syntax error because it looks like "x" x "x" to the JavaScript interpreter and that’s not JavaScript. I’m not sure which JavaScript library you’re using (Prototype perhaps?) but I think you probably want to put all your parameters into parameters to avoid having to worry about URL encoding and things like. Furthermore, there’s no reason to tell the server how many “likes” you already have and there is a good reason not to: someone might have “liked” the page while you’re looking at some the number of likes you currently have will be wrong; so hiddenLikes isn’t needed at all.

    Something like this would be better on the JavaScript side:

    new Ajax.Request("likeIt.php", {
      method:     'post', 
      parameters: { id: $('subjectId').value },
      onSuccess:  function(transport) {
          // Update the "likes" label with something like this,
          // I'm not that familiar with Prototype though so I'm
          // guessing.
          $('likes_label').update(transport.responseText);
      },
      onComplete: ????  // The function to call when it has finished.
      onFailure:  ????  // The function to call when it doesn't work.
    });
    

    And then, in the PHP, just send a simple UPDATE to the database to increment the number of likes in likeIt.php, something like this:

    <?php
    # Perform whatever authentication you need...
    if(isset($_POST["id"])) {
        # Set up your database connection and then...
        $result = mysql_query("UPDATE `subject_table` SET `likes` = `likes` + 1 WHERE `subjectId` = '" . mysql_real_escape_string($_POST["id"]) . "'");
        # Check $result and send some data back to the client (if desired), if
        # you send something back then the onComplete, onFailure, and onSuccess
        # JavaScript functions would be responsible for doing something with it.
    }
    # Send back the updated number of "likes" as text/plain.
    ?> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fairly simple question: Say I want to use 30 percent of the rows in
I have a fairly simple question: In Javascript how can I return the boolean
So this question is fairly simple, and I feel like it's kind of an
This is a fairly simple question. When you print out a LinkedList, like so:
I use PHP with CodeIgniter(MVC framework). My Question is fairly simple. What according to
Disclaimer I feel like this is a fairly simple question, so i must reiterate
A fairly simple question for which I have a guess, but I can't find
Fairly simple question: I have an init method on my class that has the
fairly simple question and I haven't seen anything asked with this exact scenario laid
I have a fairly simple question about these 2 templating engines. I'm trying to

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.