I am having what seems to be a very easy issue to resolve in my mind. I have an html form with checkbox groups and i want to be able to enforce a selection of checkboxes. At this point I just want to write an error that will come up with echo if none of the checkboxes are selected from a group. I am sending the checkbox array through a mysql query and when nothing is selected I’m getting an empty page. My confusion is how to write the PHP code to return an error. I’ve tried
if (empty($_GET){
echo "ERROR" ;}
and
if (empty($color)){
echo "ERROR" ;}
Maybe I’m just brain dead but this seems like it should work. Here is my html code that is currently working for the checkboxes.
<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
<br>
<input type="checkbox" name="pattcat[]" value="Home Decor">Home Decor
<input type="checkbox" name="pattcat[]" value="Children">Children
<input type="checkbox" name="pattcat[]" value="Tops Women">Tops Women
<input type="checkbox" name="pattcat[]" value="Accessories">Accessories
<input type="checkbox" name="pattcat[]" value="Lace">Lace
<input type="checkbox" name="pattcat[]" value="Tops Men">Tops Men
<br>
Have you tried
if( empty($_GET['color']))? Just because it’s an array doesn’t mean it’s any different to a normal GET variable.Also, make sure the form method is GET, rather than POST.