I have a basic form that has several checkboxes. When a checkbox is checked it will append the value to a url for an ajax call. After I pass these values to mypage.php?item1=1&item2=2&item3=3, I am using GET[‘item’] to retrieve and store these values in order to use in an SQL query. The complexity of this problem is the amount of values passed may vary since it is based on checkboxes. For example, you can pass 1 value or pass all three values. My question is: How can I make this dynamic that would work with the sql query? If more than one value is passed, then the query would require in the WHERE clause an AND for the additional items.
<script>
$('#submitForm').click(function() {
var url = "'www.mysite.com/mypage.php";
if ($("#checkbox_form").serialize().length > 0) {
url += "?" + $("#checkbox_form").serialize();
}
$.getJSON(url)
});
</script>
<form name="checkbox_form" id="checkbox_form">
<input type="checkbox" value="1" id="item1" name="val1" />
<input type="checkbox" value="2" id="item2" name="val2" />
<input type="checkbox" value="3" id="item3" name="val3" />
<input type="submit" id="submitForm" value="Submit Form" />
<form>
mypage.php?item1=1&item2=2
$item = $_GET['item#'];
$sql_query = "SELECT info From Products Where :item# AND item#";
$sql_prepare = $db_con->prepare($sql_query);
if (!$sql_prepare->execute(array(':item#' => $item)))
//rest of code
WHEREclause seems wrong.