p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: forms


Message #1 by "Michael Ray" <atooltoscream132@y...> on Sat, 21 Sep 2002 05:01:03
I am running php-4.2.3, I am using this code:

The HTML:

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=GET ACTION="text.php">
Who is your favourite author?
<INPUT NAME="Author" TYPE="TEXT">
<BR>
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>

The PHP:

<HTML>
<HEAD></HEAD>
<BODY>
Your favorite author is:
<?php 
echo $Author;
?>
</BODY>
</HTML>

Can anyone see why it would give me the error:

Notice: Undefined variable: Author in c:\inetpub\wwwroot\php\text.php on 
line 6

Any help would be appreciated. thanx

-michael
Message #2 by "Jacek Galach" <jgalach@p...> on Mon, 23 Sep 2002 18:20:52
turn register_globals on in php.ini file
regards,
Jack
Message #3 by "Nikolai Devereaux" <yomama@u...> on Mon, 23 Sep 2002 11:42:15 -0700
OH NO!!

> -----Original Message-----
> From: Jacek Galach [mailto:jgalach@p...]
> Sent: Monday, September 23, 2002 6:21 PM
> To: beginning php
> Subject: [beginning_php] Re: forms
> 
> 
> regards,
> Jack
Message #4 by "Nikolai Devereaux" <yomama@u...> on Mon, 23 Sep 2002 11:48:23 -0700
Ah crap, prematurely sent!  I need food/coffee..

that said, lemme clarify some things.

The reason you're getting your errors is because PHP has error_reporting set to
E_ALL by default, whereas in older versions, E_NOTICE level warnings were
suppressed.

Another change is that GET, POST, etc.. variables are not, by default, copied
into global scope.  (That is, 'register_globals = off' in php.ini).


There've been hundreds of posts on this list about $author in chapter 3,
register globals, and error reporting.


You received two replies already:

> I think that you should use the POST method, not the GET one...
> Hope it helps..

At the risk of sounding harsh, this is a useless suggestion.  You're getting
the error because $Author doesn't exist because it wasn't copied from
$_GET['Author'] into a global variable.  Changing to POST would yield the same
results for a similar reason -- the value wasn't copied from $_POST['Author'].


> turn register_globals on in php.ini file

This suggestion will fix your problem at the cost of not explaining WHY you
should or should not turn register_globals = on in php.ini.

For more info, search the list archives for register_globals, and read up on
why PHP changed the default values of error_reporting and register_globals
here:

http://www.php.net/security



Take care,

Nik


Message #5 by "Michael Ray" <atooltoscream132@y...> on Tue, 24 Sep 2002 03:20:08
thanx, Nik, i will just use $_GET instead of turning on register globals.

Michael

  Return to Index