At 12:16 22.11.2002, empty spoke out and said:
--------------------[snip]--------------------
>...
><tr>
> <td><input type="checkbox" name="val" value="a" /> AAA</td>
></tr>
><tr>
> <td><input type="checkbox" name="val" value="s" /> SSS</td>
></tr>
>...
>
>and the PHP code:
>
>$eval='';
>if(isset($val)){
>   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')";
>$result=mysql_query($sql);
>if(!$result) echo("ERROR");
>}
>
--------------------[snip]-------------------- 

Hi,

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(is_array($val)){
      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 
    ^ http://www.vogelsinger.at/

Reply via email to