I have a PHP code that runs a MySQL query to sort some output data by a filter selected.
The problem that I have is when I filter by more than 1 word, i.e. when I filter by color it works fine for RED, YELLOW, etc.. but not for BLUE NAVY.
I thought it would be enough by adding '" but it is not.
Here is my current code:
<?php
$colors = $con -> prepare("SELECT DISTINCT color_base1 FROM item_descr ORDER BY color_base1 ASC");
$colors ->execute();
while ($colorBoxes = $colors->fetch(PDO::FETCH_ASSOC))
{
echo "<input type='checkbox' class='regularCheckbox' name='color' value='".$colorBoxes[color_base1]."' /><font class='similarItemsText'> ".$colorBoxes[color_base1]."</font><br />";
}
?>
Thanks!
You need quotes around your array indexes.
Change:
$colorBoxes[color_base1]To:
$colorBoxes['color_base1']Bonus points:
Also, your form data is probably going to submit pretty weird when the input
namefield has a space in it. Try avar_dump($_REQUEST)after the form is submitted to see what the deal is, but I would suggest not using spaces in yourcolor_base1field.