You are here: Re: Simple Problem? ... Please Advise ... « All PHP « IT news, forums, messages
Re: Simple Problem? ... Please Advise ...

Posted by J.O. Aho on 12/18/05 01:54

number1.email@gmail.com wrote:
> I've tried to enter this code but I'm having some problems...please
> advise:
>
> 1) I put the following line of code in my php script:
>
> $username=$_REQUEST['username'];
>
> I get the following error:
>
> Notice: Undefined index: username in
> /export/home/mydbsite.com/public_html/index.php on line 118

Never encountered this error, no matter if I would run that in shell or
through the web server.

You could try

if (array_key_exists('username',$_REQUEST)) {
$username=$_REQUEST['username'];
}

This would first check the $_REQUEST array and see if there is key called
"username" before trying to assign the value to the variable $username.

If you still get an error message, but the script seems to work as it should,
then do

if (@array_key_exists('username',$_REQUEST)) {
$username=$_REQUEST['username'];
}

notice the '@' in front of array_key_exists(), it's there to suppress error
messages.

Don't forget to access the page with the url

http://your.host.net/~yourusername/index.php?username=yourusername


Usually you try to fetch the variables as early as possible in the script and
don't do that inside a function, as this usually can mess things up as there
is the possibility that you get a function-local array instead of the global one.



//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация