I have a jQuery that filters some items displayed in a query by color.
The problem comes with colors such as “Blue Navy”. Apparently the jQuery doesn’t pass the two words or something. When I echo results of the _GET values I never get anything when a 2 word color has been passed, while I do get my values for one-word colors.
Any idea of why this happens?
Here are my codes:
jQuery(document).ready(function($) {
$("input:checkbox").change(function() {
if($(this).is(':checked'))
{
$(".loadingItems").fadeIn(300); //fade in on change
var color = $(this).val();
$(".indexMain").load('indexMain.php?color='+color,function(){
$(".indexMain").fadeIn(slow);
})
$(".loadingItems").fadeOut(300); //remove when load is complete
}
else
{
$(".loadingItems").fadeIn(300); //fade in on change
$(".indexMain").load('indexMain.php');
$(".loadingItems").fadeOut(300); //remove when load is complete
}
});
});
$color = $_GET['color'];
$items = $con -> prepare("SELECT * FROM item_descr WHERE color_base1 = :colorbase1");
$items -> bindValue(":colorbase1", $color);
As it is a GET request, the value is appended to the querystring, and a querystring can not contain regular spaces.
You need to url encode the value before using it in the querystring:
the
$_GETsuperglobal should be automatically url decoded back in your PHP script.