title: How to set conditions for search in prepared statements?
body: <p>I am trying to create a site search in prepared statements,</p>
  <p>Here is my code : Conditions for search</p>
  <pre><code>$whereSQL = $orderSQL = ''; 
  if(!empty($_POST['keywords'])){ 
      $whereSQL = &quot;WHERE title LIKE '%&quot;.$_POST['keywords'].&quot;%'&quot;; 
  } 
  if(!empty($_POST['sortBy'])){ 
      $orderSQL = &quot; ORDER BY title &quot;.$_POST['sortBy']; 
  }else{ 
      $orderSQL = &quot; ORDER BY title DESC &quot;; 
  } 
  </code></pre>
  <p>This is how I add it to query :</p>
  <pre><code>$stmt = $pdo-&gt;prepare(&quot;SELECT * FROM posts &quot;.$whereSQL.$orderSQL); 
  $stmt-&gt;execute(); 
  $rowCount= $stmt-&gt;rowCount(); 
  </code></pre>
  <p>Here is my question.
  How can I use conditions safe way in prepared statements ?</p>