RE: weird php error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux