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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:52:35+00:00 2026-06-10T19:52:35+00:00

I would like to know if it would be possible to run an update

  • 0

I would like to know if it would be possible to run an update query when an item is selected from a drop down list. The user makes a choice, a function is then called to update a particular field in a database. This will be achieved using a select box to store the options. Thanks.

    echo '<td>';
    echo '<select name="order_status[]" onChange = "update()">';
    echo '<option value = "1" class ="pending">Pending</option>';
    echo '<option value = "2" class = "approved">Approved</option>';
    echo '<option value = "3" class ="disapproved">Disapproved</option>';
    echo '</select>';
    echo '</td>';
    echo '</tr>';
  • 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-06-10T19:52:36+00:00Added an answer on June 10, 2026 at 7:52 pm

    Yes, it’s possible. If you want the query to be run seamlessly (that is, without a submit button being pressed and the page refreshing), then you’ll need to use Ajax to send the request asynchronously to your PHP script.

    EDIT: The easiest thing to do is simply use jQuery’s $.get() functionality in your onchange event. That way, each time someone chooses an option, jQuery will send the request to your PHP script with that option’s value. The PHP script will run, and return the new data back to your jQuery, which will then use its DOM functionality to insert that data into your page.

    You can do the same thing with a button. Just stick $.get() in the button’s onclick event rather than in the select element’s onchange event.

    The jQuery site’s documentation will give you relevant code examples.

    EDIT 2: Okay, here’s a very canned example.

    First, let’s think about the actual process you want to have happen on the back end. In the simplest terms, you want to take an id from user input and use that to run in a query. Pretty straight forward (using PDO for the database work):

    // in a real app, you'd need to sanitize and validate the incoming id
    $id = $_GET['id'];
    
    $stmt = $dbh->prepare("SELECT * FROM table_name WHERE id = :id");
    $stmt->bindParam(":id", $id);
    $stmt->execute();
    
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    
    echo json_encode($row); // makes it jQuery friendly
    

    Okay, so the back end is pretty simple. Now, for the font end, where the magic happens. Here’s how I’d approach using both a select element and a button in order to pass the id back to the PHP script, and then handle the results:

    <!-- Your HTML up to where the select and button are on your page -->
    
    <select id="id" name="id">
        <option value="1">Something</option>
        <option value="2">Something Else</option>
        <option value="3">Yet Another Thing</option>
    </select>
    
    <button id="btn" />
    
    <!-- In your jQuery -->
    
    $("#btn").click(function() {
        $.get("path/to/your/back/end/script.php", { "id" : $("#id").value }, function(data) {
            /* the data will be the json_encode($row) that was echoed from the PHP script.
             * so, you'll need to drill into it, take the data you want, and use 
             * jQuery's/JavaScript's DOM manipulation tools to insert the data on your 
             * page
             */
        }) // close $.get()
    }); // close .click()
    

    None of this is tested, and it’s admittedly incomplete, but that should be more than enough to get started. Really, all you’ll need to figure out is how to drill into the returned data (it’s a JSON object, so it shouldn’t be too bad… use a browser’s web development tools to see how the data is actually formed) and insert it where you want. That, and any dumb errors I may have made above.

    Hope this helps!

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

Sidebar

Related Questions

I would like to know if it's possible to download a file from a
I would like to know whether it is possible to run a C# console
I would like to know if it is possible to run PHPUnit tests silently
I would like to run a time consuming script (to update a database from
I would like to know if it is possible to run nodeunit tests within
I would like to know how is possible to read a file placed in
I would like to know if its possible to write a nested select statment?
I would like to know if its possible to clear the current information stored
I would like to know is it possible to add css to one of
Hi I would like to know if its possible to do something similar 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.