Re: Simple Problem? ... Please Advise ...
- From: "J.O. Aho" <user@xxxxxxxxxxx>
- Date: Sun, 18 Dec 2005 00:54:09 +0100
number1.email@xxxxxxxxx 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
.
- Follow-Ups:
- Re: Simple Problem? ... Please Advise ...
- From: number1 . email
- Re: Simple Problem? ... Please Advise ...
- References:
- Simple Problem? ... Please Advise ...
- From: number1 . email
- Re: Simple Problem? ... Please Advise ...
- From: J.O. Aho
- Re: Simple Problem? ... Please Advise ...
- From: number1 . email
- Simple Problem? ... Please Advise ...
- Prev by Date: String Editing Question
- Next by Date: Re: Simple Problem? ... Please Advise ...
- Previous by thread: Re: Simple Problem? ... Please Advise ...
- Next by thread: Re: Simple Problem? ... Please Advise ...
- Index(es):
Relevant Pages
|