I have a set of checkboxes. If you click them, bits of a SQL string should be send to a php file, when a button is clicked.
The checkbox setup looks as follows:
<input type="checkbox" class="checkboxes" name="checkb[]" value="SYSTEM LIKE '%system%'">
The ajax looks as follows:
$("#button1").click(function(e) {
var category_id = {};
category_id['checkboxvalue'] = $('.checkboxes:checked').serialize();
$.ajax({
type: "POST",
url: "allgemein.php",
data: category_id,
success: function(response) {
$("#resulttable").show().html(response);
}
});
});
In php i try to call them like this:
$strWhere = '1=1';
if(true === isset($_POST['checkb']) && 0 < sizeof($_POST['checkb']))
{
$strWhere .= '(';
foreach($_POST['checkb'] as $checkboxval)
{
$strWhere .= '"'.$checkboxval.'" OR ';
}
//remove last OR
$strWhere = substring($strWhere, 0, -3);
$strWhere .= ')';
}
$strWhere
gets added to the WHERE
clause of my SQL query.
Can someone say why this is not working? $strWhere
is always 1=1, it never enters the if-loop... somehow I'm not calling the array correctly with $_POST['checkb']
and I just can't figure out why.