ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-db
php-db
RE: [PHP-DB] weird php error
by Ford, Mike [LSS] other posts by this author
Aug 29 2003 9:21AM messages near this date
Re: [PHP-DB] another PHP Sql question... | RE: [PHP-DB] another PHP Sql question...
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@[...].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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved