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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:37:09+00:00 2026-05-31T10:37:09+00:00

I have a simple option tag in html which lists all users held on

  • 0

I have a simple option tag in html which lists all users held on the database when the user clicks donate i want to take the value entered and update the dontate_Total row relvant to that user with the value entered by the user in the donate label section.

here is my html

<table>

    <form>
    <tr><td><label>User:</label></td>
    <td>
    <select>
    <?php do{?>
    <option> <?php echo $rsNames['first_Name'];?> <?php echo $rsNames['last_Name'];?></option>
    <?php } while ( $rsNames= mysql_fetch_assoc($names_query))?>
    </select>
    </td>
    </tr>
    <tr><td><label>Donation £</label></td><td><input type="text" maxlength="9" value="0.00"/></td></tr>
    <tr><td><input id="submit" type="submit" value="DONATE" /></td></tr>
    </form>
</table>

the above works fine but now I want to run and update query when the user hits the DONATE input field. here is my sql statment which I believe wont work just after some advice

$donate_sql =UPDATE `donate` SET donate_Total=  donate_Total + $_GET['value'] WHERE first_Name = 'first_Name'   AND last_Name ='last_Name';

thanks

  • 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-31T10:37:10+00:00Added an answer on May 31, 2026 at 10:37 am

    How are you?

    Edited (more profound) answer:

    In your HTML, you have to give names to your fields in order to retrieve them from your PHP script i.e. give your <select> element a name (attribute), like this:

    <select name="fullname">
    

    Also, the nested <option> elements should have a “value” attribute, this is because you almost always want the identification of a field to be a unique ID (so there’s no mistake when refering to a table row) but you want to show useful information to the user, such as a full name.

    If you plan on using an ID, then your code (in HTML) should be updated to:

    <option value="<?php echo $rsNames['id']; ?>"> <?php echo $rsNames['first_Name'];?> <?php echo $rsNames['last_Name'];?></option>
    

    This will be outputed as:

    <option value="1">John Doe</option>
    <option value="2">Jane Doe</option>
    

    Then in your PHP file, it would be much easier to write a query that updates exactly the user that you want.

    <?php
    
    $id = $_GET['fullname'];
    $donate_sql = "UPDATE `donate` SET donate_Total = donate_Total + {$_GET['value']} WHERE id = $id";
    mysql_query($donate_sql);
    
    ?>
    

    If you don’t plan on using an ID, you have to face the fact that if 2 users are called John Doe, you’ll be updating the “total” amount of donation for both of them, and it’s going to be a bit more complicated for you to parse the information.

    Say you DON’T want to use an ID and you want to stick with your first and last name, then you would write something like:

    <option value="<?php echo $rsNames['first_Name'] . '||' . $rsNames['last_Name'];?>"><?php echo $rsNames['first_Name'];?> <?php echo $rsNames['last_Name'];?></option>
    

    Which would produce an output similar to:

    <option value="John||Doe">John Doe</option>
    <option value="Jane||Doe">Jane Doe</option>
    <option value="Mary Jane||Doe">Mary Jane Doe</option>
    

    The third <option> tag is an example of why you can’t rely on spaces to parse first and last name; a person can have double name or double last name — or both, as it is in my case 😉

    The separator || is an arbitrary one, the idea is to use one or more characters that are not likely going to be used as part of the name or the last name.

    This approach (which again, is a really bad one) would require you to parse the first name and last name individually afterwards, so your script would end up being:

    <?php
    
    $name = $_GET['fullname']; //'fullname' is the name of our <select>
    $name = explode('||',$name); //this returns an array, with each position defined by the || token
    
    //$name is now an array(0=>'John',1=>'Doe') - for example.
    
    //Get the first name
    $firstName = $name[0]; //John
    
    //Get the last name
    $lastName = $name[1]; //Doe
    
    //Finally, your SQL would be updated to be:
    $donate_sql = "UPDATE `donate` SET donate_Total= donate_Total + {$_GET['value']} WHERE first_Name = '$firstName' AND last_Name ='$lastName'";
    
    mysql_query($donate_sql);
    ?>
    

    Old answer

    The quick answer is:

    $donate_sql = "UPDATE `donate` SET donate_Total = donate_Total + {$_GET['value']} WHERE first_Name = 'first_Name' AND last_Name ='last_Name'";
    

    And then using the mysql_query($donate_sql); function.

    However as @hjpotter92 pointed out, you should (amongst other things) add an ID column to that table and set it as a primary key.

    Also, you should keep in mind things like escaping values that come in your requests ($_POST and $_GET), so no SQL injection is applied to your query.

    Hope this helps!

    Cheers.

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

Sidebar

Related Questions

I have a simple html select tag with some options attached: <select> <option>school a</option>
I have simple SSIS package which reads data from flat file and insert into
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have simple SSIS package in which On Error event handler I have created
I am working on a simple movie database to practise my JavaScript and have
I want to let user add as many tag as he wants to an
I have a long press option on my listview which will delete the long
I cant figure how to simply solve this problem: So I have simple HTML
I have simple regex \.*\ for me its says select everything between and ,
I have simple win service, that executes few tasks periodically. How should I pass

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.