Re: Undefined Index
| From: | Chris Hewitt | Date: | Fri, 02 Aug 2002 13:06:36 +0000 |
| Subject: | Re: Undefined Index | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110819@lists.php.net to get a copy of this message | ||
Jrgen wrote:
$op = $_GET['op']; switch ( $op ) 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 If there is not a get variable in the url you will get the warning.
Ok, am i correct in assuming that it pops this message because $op is not defined as anything yet? Yes,
If so,should i always just do this $_POST['op'] = ''; $op = $_GET['op']; switch ( $op ) { //Code here } If there is not a get variable callled "op" you should still get the warning.
$op = isset($_GET['op']); switch ( $op ) { //Code here } Now $op will be a boolean assigned the value true (if there is a get variable called "op" in the url) or false if not. As $op will have a value then there is no warning.What I tend to do when I have an optional item of data is: if (isset($_GET["op"])) [ $op = $_GET["op"]; } else {
$op = "no value"; // set to something you can test for in your switch statement.} though there may be a better way.
Best regards from Vienna, Jrgen .. thanks, and best regards to you from Essex, England.HTH Chris