RE: [PHP] using an array with form list values
| From: | Johnson, Kirk | Date: | Thu, 03 May 2001 20:16:26 +0000 |
| Subject: | RE: [PHP] using an array with form list values | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-51321@lists.php.net to get a copy of this message | ||
Try enclosing the foreach inside an:
- if block which checks that count($preferred_location) > 0; or,
- if block which checks if it is defined, if($preferred_location).
Hopefully, one of these should work :)
Kirk
> -----Original Message-----
> From: Claudia [mailto:claudiasmt@sprynet.com]
> Sent: Thursday, May 03, 2001 2:08 PM
> To: php-general@lists.php.net
> Subject: [PHP] using an array with form list values
>
>
> I need to check that a form entry defined as an array contains a value
> before initiating the foreach code in my script.
>
> I have my form field defined in my form as:
>
> <?php
> print '
> <select
> name="preferred_location[]"size="3" MULTIPLE>
> <option value="Bermuda">Bermuda</option>
> <option value="California">California</option>
> <option value="Caribbean">Caribbean</option>
> <option value="Carolinas">Carolinas</option>
> <option
> value="Florida-Atlantic">Florida-Atlantic</option>
> <option value="Florida-Gulf
> coast">Florida-Gulf
> coast</option>
> <option value="Florida-Pan handle">Florida-Pan
> handle</option>
> <option value="Hawaii">Hawaii</option>
> <option
> value="Mediterranean">Mediterranean</option>
> <option value="Mexico">Mexico</option>
> <option
> value="S.Pacific/Autralia">S.Pacific/Autralia</option>
> </select>';
> ?>
>
> And my script code as:
>
> foreach ( $preferred_location as $location )
> {
> $msg .= "$location\n";
> }
>
> As long as the user selects at least one form value from the
> list box, the
> script processes without error. If no item is selected -- This msg is
> rcved:
>
> Warning: Non array argument supplied for foreach() in
> /usr/local/etc/httpd/htdocs/test/beaches/beaches_quote.scp.php
> 3 on line 30