I am trying to build a query that uses checkboxes from an html form. I’m not sure if i should create an array but at the current time I am only getting results from one of the checkboxes.
Here is my checkbox setup.
<input type="checkbox" name="color[]" value="Black">Black
<input type="checkbox" name="color[]" value="Blue">Blue
<input type="checkbox" name="color[]" value="Brown">Brown
<input type="checkbox" name="color[]" value="Green">Green
<input type="checkbox" name="color[]" value="Grey">Grey
<input type="checkbox" name="color[]" value="Orange">Orange
<input type="checkbox" name="color[]" value="Pink">Pink
<input type="checkbox" name="color[]" value="Purple">Purple
<input type="checkbox" name="color[]" value="Red">Red
<input type="checkbox" name="color[]" value="Teal">Teal
<input type="checkbox" name="color[]" value="White">White
<input type="checkbox" name="color[]" value="Yellow">Yellow
here is my php and mysql query
extract($_GET);
$Color = $color[];
$query = "SELECT * FROM tblYarn WHERE Color ='".$Color."'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
I’m trying to select yarn by color and only getting one color at a time.
Here is my display table code
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "<td><img src=./images/$col_value border='3' ></td>";
echo "\t</tr>\n";
}
echo "</table>\n";
This should work: