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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:26:19+00:00 2026-06-07T07:26:19+00:00

I have a small form for updating existing records. I’m loading the Service ID

  • 0

I have a small form for updating existing records.

enter image description here

I’m loading the Service IDs to the dropdown box using PHP. And when the user clicks the Load button, it is supposed to display the other details related to that ID in the textboxes below.
Here is the code I have so far.

<html>
<head>
</head>
<body>

<?php
//Database initialization
require_once("db_handler.php");

$conn = iniCon();
$db = selectDB($conn);

$query = "SELECT * FROM taxi_services ORDER BY SID";
$result2 = mysql_query($query, $conn);

?>

<div id="upserv">
<b id="caption2">Update location</b>
<br/><br/>
    <form name="upServForm" action="<?php echo $PHP_SELF; ?>" method="post" >
        <?php
        $dropdown = "<select name='codes'>";
        while($row = mysql_fetch_assoc($result2)) 
        {
            $dropdown .= "\r\n<option value='{$row['SID']}'>{$row['SID']}</option>";
        }
        $dropdown .= "\r\n</select>";
    ?>
     Service ID  <?php echo $dropdown; ?> <input type="submit" value="Load" name="loadbtn">
        <table width="300" border="0">
          <tr>
            <td>Name</td>
            <td><input type="text" name="upName" style="text-align:right" value="<? echo $savedName; ?>" /></td>
          </tr>
          <tr>
            <td>Cost</td>
            <td><input type="text" name="upCost" style="text-align:right" value="<? echo $savedCost; ?>" /></td>
          </tr>
          <tr>
            <td>Active</td>
            <td><input type="checkbox" name="upActive" value="<? echo $savedActive; ?>" /></td>
          </tr>
        </table>
</div>
<br/>
<div id="buttons">
    <input type="reset" value="Clear" /> <input type="submit" value="Save" name="updatebtn" />
</div>
    </form>

<?php

if(isset($_POST["loadbtn"]))
{
    $id = $_POST["codes"];

    $query = "SELECT Name, Cost, Active FROM taxi_services WHERE SID = '$id' ";
    $result = mysql_query($query, $conn);
    $details = mysql_fetch_array($result);

    $savedName = $details["Name"];
    $savedCost = $details["Cost"];
    $savedActive = $details["Active"];
}

?>

</body>
</html>

The query gets executed just fine but the data doesn’t get displayed in the textboxes. Can anyone please tell me what I am missing here?

Thank you.

  • 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-07T07:26:22+00:00Added an answer on June 7, 2026 at 7:26 am

    Your query has to be before the output:

    Also note the typecast (integer) of the id to secure against sql injections.

    Also note the security issues with $PHP_SELF http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm
    I changed the code to $_SERVER['SCRIPT_NAME']

    ALso note to not use register_globals and disable it in the configuration if you can (use $_SERVER['SCRIPT_NAME'] instead of$SCRIPT_NAME`) : http://www.php.net/manual/en/security.globals.php

    If you learn php from a book and this is based on sourcecode out of this book you should throw it away immediately.

    <?php
    
    //Database initialization
    require_once("db_handler.php");
    
    $conn = iniCon();
    $db = selectDB($conn);
    
    $query = "SELECT * FROM taxi_services ORDER BY SID";
    $result2 = mysql_query($query, $conn);
    
    if(isset($_POST["loadbtn"]))
    {
        $id = (integer) $_POST["codes"];
    
        $query = "SELECT Name, Cost, Active FROM taxi_services WHERE SID = '$id' ";
        $result = mysql_query($query, $conn);
        $details = mysql_fetch_array($result);
    
        $savedName = $details["Name"];
        $savedCost = $details["Cost"];
        $savedActive = $details["Active"];
    }
    
    ?>
    
    <html>
    <head>
    </head>
    <body>
    
    <div id="upserv">
    <b id="caption2">Update location</b>
    <br/><br/>
        <form name="upServForm" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" >
            <?php
            $dropdown = "<select name='codes'>";
            while($row = mysql_fetch_assoc($result2)) 
            {
                $dropdown .= "\r\n<option value='{$row['SID']}'>{$row['SID']}</option>";
            }
            $dropdown .= "\r\n</select>";
        ?>
         Service ID  <?php echo $dropdown; ?> <input type="submit" value="Load" name="loadbtn">
            <table width="300" border="0">
              <tr>
                <td>Name</td>
                <td><input type="text" name="upName" style="text-align:right" value="<? echo $savedName; ?>" /></td>
              </tr>
              <tr>
                <td>Cost</td>
                <td><input type="text" name="upCost" style="text-align:right" value="<? echo $savedCost; ?>" /></td>
              </tr>
              <tr>
                <td>Active</td>
                <td><input type="checkbox" name="upActive" value="<? echo $savedActive; ?>" /></td>
              </tr>
            </table>
    </div>
    <br/>
    <div id="buttons">
        <input type="reset" value="Clear" /> <input type="submit" value="Save" name="updatebtn" />
    </div>
        </form>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very small form where a user can enter their zip code
I have a small contact form: <form method=post action=contact.php name=contactform id=contactform> <fieldset> <legend>Please fill
Hii , I have a small php form. I need it to come in
I have a small form is to be filled in. If the user is
I have a small web form that user will enter some patient data and
I have a small form in which the user uploads a file. What I
I have a small web form which will cause a PHP script to send
I currently have a small HTML form for a third party payment service, which
I have a small form of 4 fields, I am using Ajax to save
I have created a small contact form creator in PHP and everything works fine

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.