RE: [PHP] Undefined index
| From: | dan rossi | Date: | Wed, 07 May 2003 22:17:54 +0000 |
| Subject: | RE: [PHP] Undefined index | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146738@lists.php.net to get a copy of this message | ||
i usually get those annoying errors whenever i even do $foo = "bar"; if
notice is on is it requiring just like in a class to verify the var first
like var $foo ?
-----Original Message-----
From: caspar kennerdale [mailto:caspar@thetuckshop.com]
Sent: Thursday, May 08, 2003 2:14 AM
To: php-general@lists.php.net
Subject: RE: [PHP] Undefined index
This just checks if it is set or not, but I know it is not set.
It seems to me that it is best to set it rather than cover up an error
message. using this example I would need to have action set so that the
error message does not appear when thwe page loads on default. (action is
set whenever any of the other cases are requested such as "index.php?action
=Test").
switch ($_GET['action']) {
default:
// action is not set by default so I get an error
// $action = "blah"; at the top of the page does nothing
break;
case "Test":
//action is set to "test" so no error message
break;
}
cheers
-----Original Message-----
From: Adam Voigt [mailto:adam@cryptocomm.com]
Sent: 07 May 2003 16:58
To: caspar kennerdale
Cc: php-general@lists.php.net
Subject: RE: [PHP] Undefined index
If you mean like:
switch($blah)
{
}
And your getting the warning's about $blah,
just do:
if(is_set($blah))
{
switch($blah)
{
}
}
On Wed, 2003-05-07 at 11:46, caspar kennerdale wrote:
> Thanks that 'covers' up the error message, but is there no way to give the
> index a value then when it is the default of a switch?
>
>
> Cheers
>
> Caspar
>
>
> Just at the top of your page, or in an include, put:
>
> error_reporting(E_ALL ^ E_NOTICE);
>
> (This is according to the error_reporting manual page).
>
>
> On Wed, 2003-05-07 at 11:37, caspar kennerdale wrote:
> > 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.
> >
> > How do I give action an initial value so this message does not appear
> > initally? (I dont want to rely on isps turing messaging off!)
> >
> > If this isnt possible can you turn messaging off in .htaccess in the
same
> > way you can control register globals?
> >
> >
> >
> > <?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;
> >
> > }
> >
> > ?>
> --
> Adam Voigt (adam@cryptocomm.com)
> Linux/Unix Network Administrator
> The Cryptocomm Group
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Adam Voigt (adam@cryptocomm.com)
Linux/Unix Network Administrator
The Cryptocomm Group
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php