Re: Undefined Index
| From: | Lars Olsson | Date: | Fri, 02 Aug 2002 12:53:59 +0000 |
| Subject: | Re: Undefined Index | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110813@lists.php.net to get a copy of this message | ||
Hi!
JüRgen wrote:
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 177You get this error message whenever $_GET doesn't contain anything.
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 ) {This doesn't work since the result of isset($_GET['op']) is either true or false, not a string value. You need to write it like this: if (isset($_GET['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.
//Code here} }
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ürgenHope this helps! /lasso (lasso@lassoweb.nu)