mysql - PHP: Variable showing value, even when submit button hasn't been clicked -


the scenario 1 must search code, , results appear mysql db if code present, otherwise display message "sorry, there no results found" displayed. perhaps re-enter evr no.: or double check entry."

however, before search made, error message shown.

what doing wrong?

<?php     $no_results = null;     $query = (isset($_post['query']) ? $_post['query'] : null);      $raw_results = mysql_query("select * evrdata evr_no = '$query'") or die(mysql_error());      if(mysql_num_rows($raw_results) > 0){ // if 1 or more rows returned following          while($results = mysql_fetch_array($raw_results)){                       $evr_no ='<br/>evr no. :  '.'<b>'.$results['evr_no'].'</b>';           $surname ='<br/>surname :  '.'<b>'.$results['surname'].'</b>';           $othername ='<br/>first names :  '.'<b>'.$results['othername'].'</b>';           $ps_code ='<br/>ps code :  '.'<b>'.$results['ps_code'].'</b>';          }     }     else { // if there no matching rows following         $no_results = '<br/>sorry, there no results found. perhaps re-enter evr no.: or double check entry.</b>';             }  ?> 

and on same file, in html results appear:

<form action="index.php" method="post" class="search">        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">             <div class="form-group">                 <input type="text" name="query" class="form-control" placeholder="enter evr no." required/>                  <button type="submit" id="form-submit" value="search" class="btn-submit btn btn-big dark-blue-bordered-btn">submit</button>             </div>         </div>         <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">             <?php                   if($no_results!="") // 2 times doule quotation marks is, , != means "not equal to". mean if $code not equal empty                  {                      echo $no_results;                  }                  else { echo " "; } 

i have tried isset(), empty() error message still shows though search hasn't been made.

what missing?

its rough, do. reason when page loaded, search box empty , executing query null returning 0 rows.

<?php $no_results = null; $query = (isset($_post['query']) ? $_post['query'] : null);  if ($query) {      $raw_results = mysql_query("select * evrdata evr_no = '$query'") or die(mysql_error());       if(mysql_num_rows($raw_results) > 0){ // if 1 or more rows returned following       while($results = mysql_fetch_array($raw_results)){                   $evr_no ='<br/>evr no. :  '.'<b>'.$results['evr_no'].'</b>';       $surname ='<br/>surname :  '.'<b>'.$results['surname'].'</b>';       $othername ='<br/>first names :  '.'<b>'.$results['othername'].'</b>';       $ps_code ='<br/>ps code :  '.'<b>'.$results['ps_code'].'</b>';      }   }   else{ // if there no matching rows following     $no_results = '<br/>sorry, there no results found. perhaps re-enter evr no.: or double check entry.</b>';         } } 

?>


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -