undefined var in php

undefined var in php

am 05.12.2005 18:57:58 von Arthur Knopper

Hello,

I installed easyphp, everything seems to be working ok.
now i entered this script:





Please type your name here:










You typed:

echo ($username);
?>



and i am getting this error:

Notice: Undefined variable: username

what am i doing wrong?

Thanks in advance

Arthur

Re: undefined var in php

am 05.12.2005 19:06:11 von Kimmo Laine

"Arthur Knopper" kirjoitti
viestissä:43947fea$0$37555$dbd43001@news.wanadoo.nl...
> Hello,
>
> I installed easyphp, everything seems to be working ok.
> now i entered this script:
>
>
>
>
>


> Please type your name here:

>


>
>

>
>


> You typed:
>
> > echo ($username);
> ?>
>
>
>
> and i am getting this error:
>
> Notice: Undefined variable: username
>
> what am i doing wrong?


Not a day goes by without someone asking this same thing. For Pete's sake,
where do you people find these crappy example codes? This has been a known
issue for such long time now... Okay, simply: replace $username with
$_GET['username'] and read php.net/register_globals to learn why.

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at
Kimmo Laine

Re: undefined var in php

am 05.12.2005 20:24:06 von Hilarion

> I installed easyphp, everything seems to be working ok.
> now i entered this script:
>
>
>
>
>



You have to specify "action" attribute value. It's NOT
optional. Some browsers interprete lack of the attibute
value as if it was the script address, but it's not
a rule. This attribute value is REQUIRED by HTML (at least
version 4.01) specification. If you want the script
to submit to itself, then use something like this:




> Please type your name here:

>


>
>

>
>


> You typed:
>
>
I suggest using full PHP opening tags (" short ones (" in your PHP. This will save you some problems with
including XML files (or other text files which
contain " XML (or other as above) in your PHP scripts. This
will also (in most cases) make your script blocks
more visible.


> echo ($username);

It will not work if register_globals is turned off.
Use $_REQUEST['username'] (works for data posted by
forms, passed in URLs and in cookies), or $_GET
(works for data posted by forms with no "method"
attribute specified or with "get" method specified
or passed in URLs). If you are going to use "post"
method of forms, then you'll also be able to use
$_POST.
You do not need parentheses around the echoed value.

> ?>
>
>
>
> and i am getting this error:
>
> Notice: Undefined variable: username

This means that the variable was not set. When register_globals
is turned off (which is by default now and you should not
change that), then no request parameters are placed in
global variables (they are always - regardless of register_globals
- placed in request arrays).


> what am i doing wrong?

You are using outdated tutorial / manual / examples.


Hilarion