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

  • Home
  • SEARCH
  • 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 913981
In Process

The Archive Base Latest Questions

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

I there a way to update data into mysql database when click on a

  • 0

I there a way to update data into mysql database when click on a link? I want create a comment voting system on my site so when user clicks on a “Vote for this comment” link, +1 should be sent into database…

How is that possible?

  • 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-15T17:38:38+00:00Added an answer on May 15, 2026 at 5:38 pm

    HTML

    <form method="post" action="/vote.php">
      <input type="hidden" name="item" value="999">
      <input type="submit" name="submit" value="Vote Up">
    </form>
    

    PHP – vote.php

    <?php
    if( !isset( $_POST['item'] ) ) {
      header( 'HTTP/1.0 404 Not Found' );
      die( '<html><body>Missing <i>item</i> parameter</body></html>' );
    }
    $item = (int) $_POST['item'];
    if( @mysql_query( "UPDATE `items` SET `vote`=`vote`+1 WHERE `id`=$item" ) ) {
      if( isset( $_POST['format'] ) && $_POST['format']=='json' )
        die( json_encode( array( 'result'=>true ) ) );
      die( '<html><body>Score for item #'.$item.' incremented</body></html>' );
    }
    header( 'HTTP/1.1 500 Internal Server Error' );
    if( isset( $_POST['format'] ) && $_POST['format']=='json' )
        die( json_encode( array( 'result'=>false ) ) );
    die( '<html><body>Score for item #'.$item.' FAILED to incremented</body></html>' );
    

    jQuery

    $( document ).ready( function() {
      $( 'form[action="/vote.php"]' ).each( function() {
        $( this ).replaceWith( '<span class="vote" parameter="item='+$( this ).find( 'input[name="item"]' ).attr( 'value' )+'">Vote Up</span>' );
      } );
      $( 'span[class="vote"]' ).click( function() {
        var $this = $( this );
        $.ajax( {
          type     : 'POST' ,
          url      : '/vote.php' ,
          data     : $( this ).attr( 'parameter' )+'&format=json' ,
          dataType : 'json' ,
          success  : function( data , status , XHR ) {
            if( data.result===true )
              alert( 'Voted Up' );
            else
              alert( 'Something Unexpected Borked' );
          } ,
          error    : function( XHR , status , error ) {
            alert( 'Something Borked' );
          }
        } );
      } );
    } );
    

    Note: This is an untested solution, but would be what I would consider a starting point to commence debugging and testing.

    UPDATED: Changed behaviour to POST based on advice from @Artefacto.

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

Sidebar

Related Questions

Is there a way to update more than one Database having same schema using
Is there a way to update information in a div of a parent page
Is there any way to force an update of software using RunOnce, without having
Is there a way to tell subversion update/merge unless it would cause a conflict?
Is there a way to detect when an update panel is done refreshing? I
Is there a way to exclude all svn externals when doing a recursive update?
In sql server 2005 , inside an update trigger is there a way to
update: I know there is no one best way to do everything. Sorry for
Is there way in next piece of code to only get the first record?
is there way thats i can preselect an item when the page loads or

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.