title: PHP : How to get value from DB to already created textbox
body: <h2>Background</h2>
  
  <p>I am a complete beginner to web designing and i am using PHP and mySQL.</p>
  
  <h2>Code in hand</h2>
  
  <p>This is my HTML file named <strong>UserRegistration.php</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  ?&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;script&gt;
  function FillRecord(Id)
  {
       $.ajax({
       type: "POST",
       url: "Algorithm/UserRegistration-FillUserRecords.php",
       data:'Id='+Id,
       success: function(data)
       {
          document.forms["Frm_User"].elements["txtName"].value = "";
          document.forms["Frm_User"].elements["txtFName"].value = "";
          document.forms["Frm_User"].elements["txtMName"].value = "";
       }
       });
  }
  &lt;/script&gt;
  &lt;form id="Frm_User" name="Frm_User" method="POST" action="Algorithm/UserRegistration-SaveDetails.php"&gt;
    &lt;label for="txtName"&gt;Name&lt;/label&gt;
    &lt;input type="text" name="txtName" placeholder="Name" required&gt;
  
    &lt;label for="txtFName"&gt;Father Name&lt;/label&gt;
    &lt;input type="text" name="txtFName" placeholder="Father Name" required&gt;
  
    &lt;label for="txtMName"&gt;Mother Name&lt;/label&gt;
    &lt;input type="text" name="txtMName" placeholder="Mother Name" required&gt;
  &lt;/form&gt;
  
  &lt;input type="button" onclick="FillRecord(1);"&gt;//1 is fixed at the moment
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my PHP class named <strong>UserRegistration-FillUserRecords.php</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  
  include_once 'Connection.php';
  
  if ($dbcon-&gt;connect_error)
  {
      die("Connection failed: " . $dbcon-&gt;connect_error);
      header('Location: ../UserRegistration.php');
      exit();
  }
  
  //Search data from database on all fields except "SNo"
  //----------------------------------------------------------------------------
  $sql =  "Select * from usertable where id=".$_POST["Id"];
  $result = $dbcon-&gt;query($sql);
  
  $rows = array();
  foreach ($result as $RowRecord)
  {
      $_SESSION['UserRegistration_txtName'] = $RowRecord["Name"];
      $_SESSION['UserRegistration_txtFName'] = $RowRecord["FName"];
      $_SESSION['UserRegistration_txtMName'] = $RowRecord["MName"];
  }
  exit();
  ?&gt;
  </code></pre>
  
  <p>The <strong>Algorithm/UserRegistration-SaveDetails.php</strong> is used to save the user details into database which is working perfectly.</p>
  
  <h2>Problem</h2>
  
  <p>I want to show the data which is being retrieved by <strong>UserRegistration-FillUserRecords.php</strong> into <strong>UserRegistration.php</strong>'s already created textbox when the function <strong>FillRecord</strong> is called but i have no clue as to how to assign the session variable value to my input boxes.</p>
  
  <h2>I Tried</h2>
  
  <p>1) <code>alert(&lt;?php echo $_SESSION['UserRegistration_txtName']; ?&gt;);</code>
  but the statement doesn't seem to work even when i have used</p>
  
  <p>2) <strong>success: function(data)</strong> in AJAX reponse has the value which i need but when i echo it, it shows the value in continuation like:-</p>
  
  <pre><code>abc
  ----------------
  a (Name)
  b (Father Name)
  c (Mother Name)
  </code></pre>
  
  <p>and i cant seperate it as the string can be anything, it can be full of comma's, new line characters and any special symbols</p>