At 12:16 22.11.2002, empty spoke out and said:
> <td><input type="checkbox" name="val" value="a" /> AAA</td>
> <td><input type="checkbox" name="val" value="s" /> SSS</td>
>and the PHP code:
>   if(isset($val[0]) && isset($val[1])) $eval="as";
>   if(isset($val[0]) && !isset($val[1])) $eval="a";
>   if(!isset($val[0]) && isset($val[1])) $eval="s";
>$sql="insert into maillist (ID, postmeth) values ('$id_no','$eval')";
>if(!$result) echo("ERROR");


1) like Bastian already pointed out, you need to name your checkboxes
"val[]" in order to have PHP recognize them being an array.

2) You cannot use "isset($val[0])" and "isset($val[1])". If any checkbox is
clicked, $val[0] will always be set. If only one is clicked (regardless
which one) index 0 will be set and index 1 unset.

Instead, you should
      if (in_array('a', $val) && in_array('s', $val)) $eval='as';
      elseif (in_array('a', $val))                    $eval='a';
      elseif (in_array('s', $val))                    $eval='s';

However this would give you the very same result, but much more elegant:
   $eval = join('', $val);
And it will automatically handle all further additions when $val[] might
have more possible values except 'a' and 's'.

   >O Ernest E. Vogelsinger 
   (\) ICQ #13394035 

Reply via email to