RE: [PHP] Undefined index
| From: | Ford, Mike [LSS] | Date: | Thu, 08 May 2003 09:32:40 +0000 |
| Subject: | RE: [PHP] Undefined index | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-146808@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: caspar kennerdale [mailto:caspar@thetuckshop.com]
> Sent: 07 May 2003 16:37
>
>
> I have a basic switch defining the structure of my page. (see below)
>
> Whenever the default case is loaded I get a message that
> "action" is an
> undefined index. I understand that this is because "action"
> has no value. If
> I go to any of the other cases of my switch and thus giving
> "action" a value
> then I do not get the message.
>
>
> <?php
>
> switch ($_GET['action']) {
> default:
> echo "<a
> href=\"index.php?action=Test&variable=yes\">test</a>";
>
> break;
>
> case "Test":
> $variable=$_GET["variable"];
> echo $variable;
> break;
>
> }
To me, this is an ideal occasion to use the @ operator:
switch (@$_GET['action']) {
default:
echo "<a
href=\"index.php?action=Test&variable=yes\">test</a>";
break;
case "Test":
$variable=$_GET["variable"];
echo $variable;
break;
}
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211