Re: Undefined Index
| From: | lallous | Date: | Fri, 02 Aug 2002 13:58:06 +0000 |
| Subject: | Re: Undefined Index | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110815@lists.php.net to get a copy of this message | ||
do this:
$op = isset($_GET['op']) && !empty($_GET['op']) ? $_GET['op']
: '';
"JüRgen" <uo@chello.at> wrote in message
news:20020802123613.26400.qmail@pb1.pair.com...
> It's me again, i don't mean to be a bugger, but i really like to learn as
> much as possible, that's why i ask (or will ask so many questions).
>
> Consider the following (i shortened this a lot, but it will do the trick)
>
> $op = $_GET['op'];
> switch ( $op )
> {
> case "admin":
> DoLogin();
> break;
>
> default:
> ShowHomepage();
> break;
> }
>
> PHP shoots a Notice Message telling me that there is an undefined index
> Undefined index: act in g:\apache_web\intern\looney\index.php on line 177
>
> This accects the code shown above.
>
> Ok, am i correct in assuming that it pops this message because $op is not
> defined as anything yet?
>
> If so,should i always just do this
>
> $_POST['op'] = '';
> $op = $_GET['op'];
> switch ( $op )
> {
> //Code here
> }
>
> Or would it be better and more space efficient to do this
> $op = isset($_GET['op']);
> switch ( $op )
> {
> //Code here
> }
> Cause if i do that the Notice Message dissapears for some reason i yet
fail
> to grab.
> I would really appreciate if somebody could explain to me why the Notice
> dissapears when using isset(), and also what is the best method to use
> rather then the two shown above?
> How do you guys&girls handle this?
>
> Thanks a lot in advance for your time and patience!
>
> Best regards from Vienna,
> Jürgen
>
>
>