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

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your for should be: for (int i = 0; i… May 16, 2026 at 3:41 pm
  • Editorial Team
    Editorial Team added an answer Percentage layout This is generally referred to as fluid layout.… May 16, 2026 at 3:41 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Date is the only thing the standard… May 16, 2026 at 3:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am trying to create a go-moku game using jquery,php, and mysql database. I
Just want to know if there is a way to detect how many times
Is there a way to program using pure python in Xcode? I want something
I have a thousands of data parsed from huge XML to be inserted into
Is there a way that if there's a change in records, that a query
I have a MySQL database where I am storing information that is entered from
I am working on an application that depends on a MySQL database for parts
I have a MySQL table from a third-party application that has millions of rows
I'm currently starting a new project that will display user distrubuted data links in
I read about adjustor thunk from here . Here's some quotation: Now, there is

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.