title: How to send an array of checkbox values via AJAX to PHP in the right format?
body: <p>I have a set of checkboxes, that contain bits of SQL Code in their value. If they're checked, they should be send via ajax to my php file and be embedded in my query. </p>
  
  <p>I'm only experienced with simple single variable ajax transfer and i just can't make the examples I find online via google or on stackoverflow to work.</p>
  
  <p>My ajax call:</p>
  
  <pre><code>$("#button1").click(function(e) {
      var category_id = {};
      category_id['checkboxvalue'] = $('.checkboxes:checked').serialize();
      $.ajax({
          type: "POST",
          url: "allgemein.php?id=" + Math.random(),
          dataType: "html",
          data: category_id,
          success: function(response) {
              $("#resulttable").show().html(response);
          }
      });
  });
  </code></pre>
  
  <p>My checkbox form:</p>
  
  <pre><code>&lt;input type="checkbox" class="checkboxes" name="checkb[]" value="MASTER.SYSTEM LIKE '%systemA'"&gt;System A&lt;/label&gt;
  &lt;input type="checkbox" class="checkboxes" name="checkb[]" value="(MASTER.SYSTEM LIKE '%systemB' OR MASTER.SYSTEM LIKE '%systemC')"&gt;System B/C&lt;/label&gt;
  &lt;input type="checkbox" class="checkboxes" name="checkb[]" value="MASTER.SERVICE LIKE '%serviceX%'"&gt;Service X&lt;/label&gt;
  </code></pre>
  
  <p>Now in my php I want to use the array like this:</p>
  
  <pre><code>$strWhere = '1=1';
  
  if(true === isset($_POST['checkboxvalue']) &amp;&amp; 0 &lt; sizeof($_POST['checkboxvalue']))
      {
          $strWhere .= 'AND (';
          foreach($_POST['checkboxvalue'] as $checkboxval)
          {
              $strWhere .= '"%'. $checkboxval .'%" OR ';
          }
          //remove last OR
          $strWhere = substring($strWhere, 0, -3);
          $strWhere .= ')';
      }
  </code></pre>
  
  <p>Then add $strWhere to my SQL Where clause. </p>