title: With PHP MYSQL Prepared Statements and IFNULL() to return all records if value = ""
body: <p>I am trying to build a MySQL query using Prepared Statements that will ignore a criteria if it has been set to NULL. For example, in the below, if <code>$a = ""</code> and <code>$b = "10"</code>, I want the query to return all records where column b contains the value 10 and ignore the a criteria, because currently, the query would return all records that have a 'column a' value of "" and a 'column b' value of "10".</p>
  
  <pre><code>    if ($stmt = $mysqli-&gt;prepare("SELECT x, y FROM users WHERE a = IFNULL(?, %%) AND b = IFNULL(?, %%) AND ...")) { 
      $stmt-&gt;bind_param('ss...', $a, $b, ...); // Bind variables to parameter.
      $stmt-&gt;execute(); // Execute the prepared query.
      $stmt-&gt;store_result();
      }
  </code></pre>
  
  <p>What should I replace '%%' with to return everything as if the criteria had not been set?</p>
  
  <p>EDIT: Found an answer here that doesn't use prepared statements, but instead an array of allowed strings for security to stop SQL injections.</p>
  
  <p><a href="https://stackoverflow.com/questions/9561878/multiple-dropdowns-dynamic-query-ajax-php-mysql">Multiple Dropdowns Dynamic Query AJAX PHP MySQL</a></p>