title: retrieve sql data & print it into form field
body: <p>here is an example that if i enter id then it will retrieve data from database &amp; print it within form fields. my database has only three column- id, name &amp; number. here is my index.html file:</p>
  
  <pre><code>    &lt;html&gt;
  
  &lt;head&gt;
  
      &lt;script&gt;
  
          function showData(str)
          {
              if (str=="")
              {
                  document.getElementById("ajax-content").innerHTML="";
                  return;
              } 
  
              // Code for IE7+, Firefox, Chrome, Opera, Safari
              if (window.XMLHttpRequest)
              {
                  xmlhttp=new XMLHttpRequest();
              }
  
              // Code for IE6, IE5
              else
              {
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
  
              xmlhttp.onreadystatechange=function()
              {
                  if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
                  {
                      document.getElementById("ajax-content").innerHTML=xmlhttp.responseText;
                  }
              }
  
              xmlhttp.open("GET","showData.php?id="+str,true);
  
              xmlhttp.send();
  
          }
          return true;
  
      &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
      &lt;p&gt;Please Enter Your Staff ID:&lt;/p&gt;
      &lt;div&gt;&lt;input onkeyup="if (event.keyCode == 13) showData(this.value); return false;" /&gt;&lt;/div&gt;
  
  
  
  &lt;div id="ajax-content"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and here is my showData.php file:</p>
  
  <pre><code>    &lt;?php
  
      // Receive variable from URI
      $id=$_GET["id"];
  
      // Connect to your database
      $con = mysql_connect('localhost', 'root', '');
      if (!$con)
      {
          die('Could not connect: ' . mysql_error());
      }
  
      // Select your database
      mysql_select_db("test_01", $con);
  
      // Select all fields from your table
      $sql="SELECT * FROM staffdetails WHERE id = '".$id."'";
  
      $result = mysql_query($sql);
  
      while($row = mysql_fetch_array($result))
      {
  
          echo "Staff Name:" . "&lt;input type='text' value='" . $row['name'] . "'&gt;";
          echo "&lt;/br&gt;";
          echo "Contact No.:" . "&lt;input type='text' value='" . $row['number'] . "'&gt;";
      }
  
      // Close the connection
      mysql_close($con);
  
  ?&gt;
  </code></pre>
  
  <p>now what i'm trying to do is, display the data in a given form field rather than print data with the form field. that means, the name &amp; number input field will be already in the form with the id field. when i'll enter id then it will pull back the data &amp; display it in the given form field. anyone can help please? thanks!</p>