You are here: Re: How to get rid of warnings? « PHP Programming Language « IT news, forums, messages
Re: How to get rid of warnings?

Posted by Jerry Stuckle on 12/09/17 11:56

Lenard Redwood wrote:
> I have the maximum number of warnings during PHP development. How can I
> get rid of these warnings without turning them off in PHP?
>
> Here's the code I have:
>
> <form method="POST" action="eat.php">
> <select name="lunch[ ]" multiple>
> <option value="pork">BBQ Pork Bun</option>
> <option value="chicken">Chicken Bun</option>
> <option value="lotus">Lotus Seed Bun</option>
> <option value="bean">Bean Paste Bun</option>
> <option value="nest">Bird-Nest Bun</option>
> </select>
> <input type="submit" name="submit">
> </form>
>
> Selected buns: <br/>
> <?php
> foreach ($_POST['lunch'] as $choice) {
> print "You want a $choice bun. <br/>";
> }
> ?>
>
>
> And I get: Warning: Invalid argument supplied for foreach() in
> C:\lighttpd\htdocs\index.php on line 17
>
> Is there a way to give the 'lunch' variable a default value if
> undefined?
> Thank you.
>

Make sure $_POST['lunch'] is set and is an array. Check out isset() and
is_array().

And ALWAYS validate information coming from the user. NEVER assume
you're getting something.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация