title: Getting data from a input textfield then use it in MySQL statement on the same page
body: <p>sorry for the bulk of code :)</p>
  
  <p>I need to input a client name in the input textfield name clientname then i need to output the client information from my database when i click a button name loadcliinfo. But the problem is <strong> i don't know how will i get the data inputted in clientname? </strong> so I used <strong>$_POST['clientname']</strong>. The code is not working.</p>
  
  <p>the code i pasted below is located on the same file.</p>
  
  <pre><code>       &lt;tr&gt;
            &lt;td width="6"&gt;&lt;/td&gt;
            &lt;td width="155"&gt;Client Name&lt;font color="#990000"&gt;*&lt;/font&gt;&lt;/td&gt;
            &lt;td width="218"&gt;&lt;input type="text" name="clientname" id="clientname" required= "required" class="forinput" value="&lt;?php echo $clientname ?&gt;"/&gt;&lt;/td&gt;
             &lt;td width="148"&gt;&lt;input type="button" name="loadcliinfo" value="Load Client Info" onClick="loadclientinfo()"/&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td width="6"&gt;&lt;/td&gt;
              &lt;td width="155"&gt;Client Address&lt;font color="#990000"&gt;*&lt;/font&gt;&lt;/td&gt;
              &lt;td width="218"&gt;&lt;p id="clientadd" class="readonly"&gt;&lt;/p&gt;&lt;/td&gt;
              &lt;td width="148"&gt;Contact Name&lt;font color="#990000"&gt;*&lt;/font&gt;&lt;/td&gt;
              &lt;td width="230"&gt;&lt;p id="clientcontactname" class="readonly"&gt;&lt;/p&gt;&lt;/td&gt;
              &lt;td width="8"&gt;&lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr class="shade"&gt;
              &lt;td width="6"&gt;&lt;/td&gt;
              &lt;td width="155"&gt;Email Address&lt;font color="#990000"&gt;*&lt;/font&gt;&lt;/td&gt;
              &lt;td width="218"&gt;&lt;p id="clientemail" class="readonly"&gt;&lt;/p&gt;&lt;/td&gt;
              &lt;td width="148"&gt;Contact No&lt;font color="#990000"&gt;*&lt;/font&gt;&lt;/td&gt;
              &lt;td width="230"&gt;&lt;p id="clientaddcontact" class="readonly"&gt;&lt;/p&gt;&lt;/td&gt;
              &lt;td width="8"&gt;&lt;/td&gt;
            &lt;/tr&gt;
  </code></pre>
  
  <p><strong>my php code</strong>                   </p>
  
  <pre><code>      &lt;?php
                  $name=isset($_POST['clientname'])? $_POST['clientname'] : '';
  </code></pre>
  
  <p>I get the data using this statement <strong>isset($_POST['clientname'])? $_POST['clientname'] : '' </strong> and store it in the variable $name but when i output the variable its empty. </p>
  
  <pre><code>                $csql="Select address, email, contactperson, contactno from client where name='$name'";
                  $result=$db-&gt;prepare($csql);
                  $result-&gt;execute();
                  while($resu= $result-&gt;fetch(PDO::FETCH_ASSOC))
                      {
                         echo '&lt;input type="hidden" id="add" value="'.$resu['address'].'"/&gt;';
                          echo '&lt;input type="hidden" id="email" value="'.$resu['email'].'"/&gt;';
                          echo '&lt;input type="hidden" id="contactperson" value="'.$resu['contactperson'].'"/&gt;';
                          echo '&lt;input type="hidden" id="contactno" value="'.$resu['contactno'].'"/&gt;';    
                        }
                  ?&gt;
  </code></pre>
  
  <p><strong>My loadclientinfo function</strong></p>
  
  <pre><code> &lt;script&gt;
    function loadclientinfo()
      { 
          var add=document.getElementById("add");
          var email=document.getElementById("email");
          var contactperson=document.getElementById("contactperson");
          var contactno=document.getElementById("contactno");
  
          document.getElementById("clientadd").innerHTML = add.value;
          document.getElementById("clientemail").innerHTML = email.value;
          document.getElementById("clientcontactname").innerHTML = contactperson.value;
          document.getElementById("clientcontact").innerHTML = contactno.value;
  
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I think <strong>getting data from clientname is the problem.</strong> Is there any way i could get the data from clientname on the same page?
  thanks :D </p>