title: php retrieve data from mySQL database into form
body: <p>I have a registration form, and what I like to so is to use a mySQL query to retrieve data in to the form input fields. </p>
  
  <p>this is part of the very long form:</p>
  
  <pre><code>&lt;form class="form-horizontal" id="registration" method='post' action='ConnectDB.php' onsubmit='return ValidateForm(this);'&gt;
      &lt;fieldset&gt;
          &lt;h1 style="margin-top: px;float:right; color:#62A1D5"&gt;&lt;br&gt;&lt;b&gt;registration&lt;/b&gt;&lt;/h1&gt;
          &lt;table id="TBackGround"&gt;
              &lt;td style="padding-left:10px; padding-right:10px;"&gt;
                  &lt;p id="pd"  style="margin-top:5px; margin-right:2px; font-size:16px; text-decoration:underline"&gt;&lt;b&gt;&lt;br&gt;details:&lt;/b&gt;&lt;p&gt; 
                  &lt;p style="line-height: 1.3em" class="details"&gt;
                  &lt;div class="control-group"&gt; 
                      &lt;label class="control-label"&gt;ID &lt;/label&gt;
                      &lt;input type="text"name="studentID"  align= "right" class="textbox" &gt;&lt;span id="errorID"&gt;&lt;/span&gt; &lt;br/&gt;  
                  &lt;/div&gt;
                  &lt;div class="control-group"&gt; 
                      &lt;label class="control-label" &gt;First name&lt;/label&gt;
                      &lt;input type="text" name="Fname"  class="textbox" &gt;&lt;span id="errorFirstName"&gt; &lt;br/&gt;
                  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>How do I set the retrived data to be loaded in to the form's input fields?
  What I have is a query to retrieve the ID of the record but I don't know how to set the entire query result on to the fields.</p>
  
  <p>my php query:</p>
  
  <pre><code>&lt;?php 
  
  if(isset($_POST['submit']))
  {
  $query = $_POST['query']; 
  $min_length = 1;
  if(strlen($query) &gt;= $min_length)
  { 
  $query = htmlspecialchars($query); 
  $query = mysql_real_escape_string($query); 
  echo "&lt;table border='0' width='300' align='center' cellpadding='1' cellspacing='1'&gt;";
  echo "&lt;tr align='center' bgcolor='#002C40'&gt; 
  ?&gt;
  &lt;td height='35px' width='150px'&gt;id&lt;/td&gt; &lt;td&gt;first name&lt;/td&gt;
  
  &lt;/tr&gt;"; 
  $raw_results = 
  
  mysql_query("SELECT * FROM student WHERE (`idStudent` LIKE '%".$query."%') OR (`FirstName` LIKE '%".$query."%')"); 
  if(mysql_num_rows($raw_results) &gt; 0)
  {
  while($results = mysql_fetch_array($raw_results))
  { 
  
  echo "&lt;tr align='center' bgcolor='#0f7ea3'&gt;
  
   &lt;td height='25px'&gt; "
   .$results['idStudent']."&lt;/td&gt; &lt;td&gt;".$results['FirstName']."&lt;/td&gt;
  
  
  
  
  
  
  &lt;/tr&gt;" ;
  }
  
  }
  else{ 
  echo "&lt;tr align='center' bgcolor='#6C0000'&gt;
  
  &lt;td colspan='2' height='25px'&gt;No results&lt;/td&gt;&lt;tr&gt;"; 
  echo "&lt;/table&gt;"; 
  } 
  }
  else{ 
  echo "Minimum length is ".$min_length;
  }} 
  
  ?&gt;
  </code></pre>