RE: [PHP-DB] weird php error
| From: | Ford, Mike [LSS] | Date: | Fri, 29 Aug 2003 09:21:45 +0000 |
| Subject: | RE: [PHP-DB] weird php error | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-30220@lists.php.net to get a copy of this message | ||
On 29 August 2003 06:39, OpenSource wrote:
> Hi guys,
>
> This is weird to me..
> I got this script
> --------------------------------------------------- <?php
>
> if ($_GET[login] == 'forgot')
> {
> echo "Sorry I forgot my password";
> } else { echo "you are good to go"; }
>
> >
> -------------------------------------------------
> when ran, it gives me this error
>
> ------------------------------------------------
> Notice: Use of undefined constant login - assumed 'login' in
> G:\Inetpub\wwwroot\test\index.php on line 3
This is because you haven't quoted the array subscript -- PHP thinks you're
trying to refer to a constant called login, but on not finding that assumes
that you meant the string 'login' instead. To suppress this notice, supply
the subscript correctly as a string:
if ($_GET['login'] == 'forgot')
>
> Notice: Undefined index: login in G:\Inetpub\wwwroot\test\index.php
> on line 3
This means that there was no login= parameter on the URL that called this
script. If this is a permissible condition, you need to allow for it in
your code. One way is simply to suppress the error message with the @
operator:
if (@$_GET['login'] == 'forgot')
Another is to do more explicit checking:
if (isset($_GET['login']) && $_GET['login'] == 'forgot')
Which you use is really down to personal preference.
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