You are here: Re: $_POST « PHP « IT news, forums, messages
Re: $_POST

Posted by Adam Hubscher on 01/17/05 10:52

Andrew Maxwell wrote:
> When you submit something, and you want to make sure that the user
> inputs all of the info, is there an easier way to do it than this:
>
> if ((!$_POST[name]) || !$_POST[pass]) || (!$_POST[blah]))
> {
> etc.....
> }
>
> is there an easy way to check if all of the varibles have data in them?
>
> ~Andrew

Well, you could use a simple foreach:

foreach ($_POST as $key => $value){

if($value === '') { print("You must fill in all the values");}
else{continue;}
}

I'm not sure if empty($value); would work, but its worth a try.

You could however use it, within the foreach by doing:

empty($_POST[$key]);

(if $key = name, it would test $_POST[$name] whether it is empty or not).

http://us2.php.net/manual/en/function.empty.php

I would assume that empty() would work in this case eitherway, and is
most likely your best bet.

However, within this function it may also be smart to include a few form
validation rules for the security of your form as well.

 

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

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