On Thu, 21 Mar 2002, Joshua E Minnie wrote:
> I need to access a variable on a form that allows multiples.  I have to use
> $HTTP_POST_VARS so I need to know how to display the information obtained
> from the form.  This is what I am using right now:
> <?
>   reset($HTTP_POST_VARS["interest"]);
>   while(current($HTTP_POST_VARS["interest"])) {
>     echo strip_tags(trim($HTTP_POST_VARS["interest"]))."&nbsp;&nbsp;&nbsp;";
>     next($HTTP_POST_VARS["interest"]));
>   }
> ?>
> Both $HTTP_POST_VARS["interest"] and $HTTP_POST_VARS["interest[]"] throw
> errors.  Any suggestions would be greatly appreciated.

1. Make sure you defined the form element in your HTML as "interest[]" and
not "interest".

2. Test to see that it's an array before trying to run loop through it,
because if the user doesn't select anything, you won't get an array, and
therefore referring to to the variable as one would be an error.

if (is_array($HTTP_POST_VARS['interest']))
  foreach ($HTTP_POST_VARS['interest'] as $item)
    echo strip_tags(trim($item)) . '&nbsp;&nbsp;&nbsp;';        


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to