You are here: Re: undefined var in php « PHP SQL « IT news, forums, messages
Re: undefined var in php

Posted by Hilarion on 12/05/05 21:24

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

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:

<form method="get" action="<?php
echo htmlspecialchars( $_SERVER['PHP_SELF'] );
?>">


> Please type your name here:<br>
> <input type=text name="username"><br><br>
> <input type=submit value="Submit data">
> </form>
>
> <br><br>
> You typed:
>
> <?

I suggest using full PHP opening tags ("<?php") not
short ones ("<?") and turning OFF short tags support
in your PHP. This will save you some problems with
including XML files (or other text files which
contain "<?" character combination) or writing
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.

> ?>
>
> <html>
>
> 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

 

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

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