title: Load data from MySQL database to HTML textboxes on button click
body: <p>I have a small form for updating existing records. </p>
  
  <p><img src="https://i.stack.imgur.com/6kxwv.png" alt="enter image description here"></p>
  
  <p>I'm loading the <strong>Service ID</strong>s to the dropdown box using PHP. And when the user clicks the <em>Load</em> 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.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?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);
  
  ?&gt;
  
  &lt;div id="upserv"&gt;
  &lt;b id="caption2"&gt;Update location&lt;/b&gt;
  &lt;br/&gt;&lt;br/&gt;
      &lt;form name="upServForm" action="&lt;?php echo $PHP_SELF; ?&gt;" method="post" &gt;
          &lt;?php
          $dropdown = "&lt;select name='codes'&gt;";
          while($row = mysql_fetch_assoc($result2)) 
          {
              $dropdown .= "\r\n&lt;option value='{$row['SID']}'&gt;{$row['SID']}&lt;/option&gt;";
          }
          $dropdown .= "\r\n&lt;/select&gt;";
      ?&gt;
       Service ID  &lt;?php echo $dropdown; ?&gt; &lt;input type="submit" value="Load" name="loadbtn"&gt;
          &lt;table width="300" border="0"&gt;
            &lt;tr&gt;
              &lt;td&gt;Name&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="upName" style="text-align:right" value="&lt;? echo $savedName; ?&gt;" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Cost&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="upCost" style="text-align:right" value="&lt;? echo $savedCost; ?&gt;" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Active&lt;/td&gt;
              &lt;td&gt;&lt;input type="checkbox" name="upActive" value="&lt;? echo $savedActive; ?&gt;" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
  &lt;/div&gt;
  &lt;br/&gt;
  &lt;div id="buttons"&gt;
      &lt;input type="reset" value="Clear" /&gt; &lt;input type="submit" value="Save" name="updatebtn" /&gt;
  &lt;/div&gt;
      &lt;/form&gt;
  
  &lt;?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"];
  }
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>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?</p>
  
  <p>Thank you.</p>