Re: Undefined index

From: Date: Thu, 08 May 2003 06:30:27 +0000
Subject: Re: Undefined index
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146787@lists.php.net to get a copy of this message
Hi, Thursday, May 8, 2003, 1:37:02 AM, you wrote: ck> I have a basic switch defining the structure of my page. (see below) ck> Whenever the default case is loaded I get a message that "action" is an ck> undefined index. I understand that this is because "action" has no value. If ck> I go to any of the other cases of my switch and thus giving "action" a value ck> then I do not get the message. ck> How do I give action an initial value so this message does not appear ck> initally? (I dont want to rely on isps turing messaging off!) ck> If this isnt possible can you turn messaging off in .htaccess in the same ck> way you can control register globals? ck> <?php ck> switch ($_GET['action']) { ck> default: ck> echo "<a ck> href=\"index.php?action=Test&variable=yes\">test</a>"; ck> break; ck> case "Test": ck> $variable=$_GET["variable"]; ck> echo $variable; ck> break; ck> } ?>> I would do it like this: $action = (isset($_GET['action))? $_GET['action'] : 'None'; switch ($action) { case 'None': echo "<a href=\"index.php?action=Test&variable=yes\">test</a>"; break; case "Test": $variable = (isset($_GET['variable']))? $_GET['variable'] : 'Not Set'; echo $variable; break; } -- regards, Tom

« previous php.general (#146787) next »