title: Filter data by multiple text boxes in php
body: <p>I have five textboxes which are associated with its own field from the my sql database.What I want to do is fetch data from the mysql database depending on what the user has entered in the text box.Below is my HTML coding.</p>
  
  <pre><code>&lt;html&gt;
      &lt;form method="POST" action="t14.php"&gt;                        
          Device IP&lt;input type="text" name="D_ip"  size="7%"/&gt;&lt;br/&gt;
          Device Name&lt;input type="text" name="name" size="22%" /&gt;&lt;br/&gt;
          Interface&lt;input type="text" name="state" size="22%"/&gt; &lt;br/&gt;
          &lt;input type="submit" name="submit" value="Filter"/&gt;                 
      &lt;/form&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I want to retrieve data by matching all filed text in the text boxes. If any text box is empty it should skip. I tried with following php coding. But it is not working.Any one know what is the reason. </p>
  
  <pre><code>    &lt;html&gt;
  
      &lt;?php
          $servername = "localhost";
          $username = "root";
          $password = "901230358v";
          $dbname = "my";
  
          // Create connection
          $conn = new mysqli($servername, $username, $password, $dbname);
          // Check connection
          if ($conn-&gt;connect_error) {
              die("Connection failed: " . $conn-&gt;connect_error);
          } 
  
  if(isset($_POST['submit'])){
  
              $name = (!empty($_POST['D_ip']) ? mysql_real_escape_string($_POST['D_ip']) : false);
              $total_marks = (!empty($_POST['name']) ? mysql_real_escape_string($_POST['name']) : false);
              $rank = (!empty($_POST['state']) ? mysql_real_escape_string($_POST['state']) : false);
  
              $sql = "SELECT * FROM 'details' WHERE 1=1";
  
              if($name){
                  $sql.=" AND 'IP' = ".$name;
              }
  
              if($total_marks){
                  $sql.=" AND 'Name' = ".$total_marks;
              }
  
              if($rank){
                  $sql.=" AND 'State' = ".$rank;
              }
  
              $result = $conn-&gt;query($sql); 
  
              if ($result-&gt;num_rows &gt; 0) {
                  // output data of each row
                  while($row = $result-&gt;fetch_assoc()) {
                      echo "ip: " . $row["IP"]. " - Name: " . $row["Name"]. " -State: " . $row["State"]. "&lt;br&gt;";
                  }
              } 
              else {
                  echo "0 results";
              }
              $conn-&gt;close();
      } 
      ?&gt;
      &lt;/html&gt;
  </code></pre>