title: multiple checkboxes used for search in php and mysql?
body: <p>This seems to be a common question as I have seen plenty of similar questions.</p>
  
  <p>however, none of the answers actually pointing out how to do the selecting from mysql database and this is my issue as the moment.</p>
  
  <p>basically I have a table which I store the search data in it.</p>
  
  <p>it looks like this:</p>
  
  <pre><code>id    blond   darkHair    busty     curvy
  ---------------------------------------------------
  
  1     blond               busty
  
  2             dark hair   busty     curvy
  
  3     blond                         curvy
  
  4     blond                         curvy
  </code></pre>
  
  <p>and I have a form with checkboxes like so:</p>
  
  <pre><code>&lt;form action="search.php" method="post"&gt;
      &lt;input name="keyword[]" type="checkbox" value="blond"  /&gt;
      &lt;input name="keyword[]" type="checkbox" value="dark hair" /&gt;
      &lt;input name="keyword[]" type="checkbox" value="busty"  /&gt;
      &lt;input name="keyword[]" type="checkbox" value="curvy"  /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and the PHP codes like this:</p>
  
  <pre><code>if(isset($_POST['keyword']))
  {
  
      $keyword = $_POST['keyword'];
  
   foreach ($_POST['keyword'] as $keyword) {
  
     $keywordarray[] = mysqli_real_escape_string($conx, $keyword);
  
  
      }
     $keywords = implode (",", $keywordarray);
  
      $sql = "SELECT * FROM girlsStaff
              WHERE (`blond` LIKE '%".$keyword."%') OR (`darkHair` LIKE '%".$keyword."%') OR (`busty` LIKE '%".$keyword."%') OR (`thin` LIKE '%".$keyword."%')" or die();
  
  
      $query = mysqli_query($conx, $sql);
  </code></pre>
  
  <p>Now, apart from converting this code to PDO or prepared statement, there is another issue which I don't understand!</p>
  
  <p>it doesn't matter how many chechboxes i select... it always returns the result for last checked/selected checkbox value from mysql database....</p>
  
  <p>is there something that I am missing?</p>
  
  <p>i also, did <code>echo $keywords</code> at the top of my page to see whats being sent to the page and I get the value of all the selected/checked boxes being sent correctly.. so I know the issue is not there.</p>
  
  <p>any help or advice would be appreciated.</p>