title: How to retrieve the stored  database data (i.e data  selected from dropdown ) as  selected data in the dropdown
body: <p>What i have done till now was to store the dropdown selected  data into the database , what i now would like is based on the username typed in the textbox and clicked on search button , the dropdown item to be selected  is  to be the data stored in the database along with a list of values which  user should be able to choose if he wishes . </p>
  
  <p>I just want to know how to replace the text   Select  from here  with the selected data coming from the database as well as allow the user to edit the data as he wants in the dropdown and save it again in the database once he clicks the submit button .</p>
  
  <p>Code While storing data is as follows </p>
  
  <pre><code>&lt;?php
  if( $_POST['registerbtn']){
  $getuser=    mysql_real_escape_string(trim($_POST['user']));
  $selected_value = $_POST['selectID'];
  if($selected_value != 0){
  require("./connect.php");
  $query=mysql_query("SELECT * FROM user_details WHERE username='$getuser'");
  $numrows= mysql_num_rows($query);
  if($numrows == 0) { 
  mysql_query("INSERT INTO user_details  VALUES (  '','$getuser','$selected_value')");
  }
   else
  $errormsg = "There is already a user with that username ." ;
  mysql_close();
  }
  else
   $errormsg = "You  must select a linecard";
  }
  //code to fill dropdown 
  require("./connect.php");
  $sql = "SELECT select_id, linecard_name FROM selection ". "ORDER BY linecard_name";
  $rs = mysql_query($sql);
  $options = "&lt;option value = '0'&gt;  Select  from here &lt;/option&gt;";
  while($rownw = mysql_fetch_array($rs)){
  $options .= "&lt;option value = ".$rownw['select_id']." &gt; ".$rownw['linecard_name']. " &lt;/option&gt; ";
  }
  mysql_close() ;
  
  $form = "&lt;form action='./reg.php'  method='post'&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;  &lt;/td&gt;
  &lt;td&gt;  &lt;font color='red'&gt; $errormsg &lt;/font&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;  Username  &lt;/td&gt;
  &lt;td&gt;  &lt;input type='text' name='user'  value='$getuser' /&gt;  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt; Select  Linecard &lt;/td&gt;
  &lt;td&gt;  &lt;Select name='selectID' &gt; $options  &lt;/select&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;   &lt;/td&gt;
  &lt;td&gt;  &lt;input type='submit' name='registerbtn' value='Register' /&gt;  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/form&gt;";
  
  echo $form;
  ?&gt;      
  </code></pre>
  
  <p>Code while retrieving the data from the database to the dropdown based on username written in textbox is as follows </p>
  
  <pre><code>&lt;?php
  if( $_POST['savebtn']){
  $search = $_POST['search'];
  if($search == '' )
  {
  $errormsg1 = "Enter something in the search box";
  }
  else
  {
  require("./connect.php");
  $query = mysql_query("SELECT  * FROM user_details  WHERE  username = '$search'");
  $numrows= mysql_num_rows($query);
  $rows=mysql_fetch_assoc($query);
  if($numrows == 1)
  {
  $getuser = $rows['username'];
  $select_id= $rows['linecard_id'];
  //selection table where linecard_name is stored along with select_id   for the linecard_name to be displayed 
  $query1  = mysql_query("SELECT *  FROM selection  WHERE  select_id = '$select_id' ") ;
  $rows1=mysql_fetch_assoc($query1);
  $linecard_name= $rows1['linecard_name'];
  echo $linecard_name;
  
  $sql = "SELECT select_id, linecard_name FROM selection ". "ORDER BY linecard_name";
  $rs = mysql_query($sql);
  while($rownw = mysql_fetch_array($rs)){
  if( $select_id == $rownw['select_id'])  {
  echo $select_id;
  $options .= "&lt;option value = ". $select_id ." &gt; " .$linecard_name. " &lt;/option&gt; ";
  }
  }
  
  }
  else
  $errormsg1 = "Username was Not found";
  mysql_close() ;
  }
  }
  
  ?&gt;
  
  &lt;?php
  $form ="&lt;form action='ad.php' method='post' id='search' &gt;
  &lt;div class='place'&gt;
  &lt;tr&gt;
  &lt;td&gt;  &lt;/td&gt;
  &lt;td&gt;  &lt;font color='red' &gt; $errormsg1 &lt;/font&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;div class='frm2'&gt; &lt;input  type='text'  size='15'  value='$search'  name='search'    /&gt; &lt;/div&gt;
  &lt;div class='frm3'&gt;      &lt;input type='submit'   name='savebtn'  /&gt; &lt;/div&gt;
  &lt;div class='clear'&gt; &lt;/div&gt;
  &lt;/div&gt; 
  &lt;/form&gt;";
  echo $form;
  ?&gt;
  
  &lt;?php
  require("./connect.php");
  $sql = "SELECT select_id, linecard_name FROM selection "."ORDER BY linecard_name";
  $rs = mysql_query($sql);
  $options = "&lt;option value = '0'&gt;  Select  from here &lt;/option&gt;";
  while($rownw = mysql_fetch_array($rs)){
  $options .= "&lt;option value = ".$rownw['select_id']." &gt; ".$rownw['linecard_name']. " &lt;/option&gt; ";
  }
  mysql_close() ;
  $form = "&lt;form action='./reg.php'  method='post'&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;  &lt;/td&gt;
  &lt;td&gt;  &lt;font color='red'&gt; $errormsg &lt;/font&gt; &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;  Username  &lt;/td&gt;
  &lt;td&gt;  &lt;input type='text' name='user'  value='$getuser' /&gt;  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt; Select  Linecard &lt;/td&gt;
  &lt;td&gt;  &lt;Select name='selectID' &gt; $options  &lt;/select&gt; &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;   &lt;/td&gt;
  &lt;td&gt; &lt;input type='submit' name='savebtn' value='Save' /&gt;   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/form&gt;";
  echo $form;
  ?&gt;
  </code></pre>