title: Only one parameter being queried in a prepared statement with multiple fields
body: <p>I am getting values from multiple form fields and using a prepared statement to query the database. While the code below works for criteria entered in a single field, it doesn't return any values if I enter in more than one field. It seems the reason is that page is only processing the last field entered. when I <code>echo</code> the value in <code>$params</code> before <code>$results-&gt;execute(array($params));</code> I only get one value...</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>&lt;?php
  
  
  $dbhost     = "ip_address";
  $dbname     = "db_name";
  $dbuser     = "db_login";
  $dbpass     = "db_pass"; 
  
  $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
  
      $query = "SELECT * FROM tbl_name WHERE 1=1";
  
      foreach ($_POST as $k =&gt; $v) 
      { 
        if(!empty($v)) {
          $query .= " AND $k LIKE ?";
          $params[] = '%'.$v;     
        }  
      }   
  
      $results = $conn-&gt;prepare($query);
      $results-&gt;execute($params);
  
      $results-&gt;bindColumn(1, $no);
      $results-&gt;bindColumn(2, $date);
      $results-&gt;bindColumn(3, $name);
      $results-&gt;bindColumn(4, $id);
      $results-&gt;bindColumn(5, $path);
  
  ?&gt;
  </code></pre>
  
  <h2>EDIT:</h2>
  
  <p>I changed the code above to the working script</p>