Click to See Complete Forum and Search --> : script problems


climberfreak2003
09-08-2002, 11:50 AM
I just started reading this book on php and im having trouble with one of its' examples. Here is the code:
FIRST PAGE

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


SECOND PAGE


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

When I hit the "Submit Query" button on the first page the php page tells me that the variable Author is undefined. The variables are exactly the same between the two pages, i don't know what else could be going wrong. Any help would be great.

Grizzly
09-08-2002, 12:04 PM
On your second page try this instead:


Your favorite author is:
<?php echo $_GET['Author']; ?>


PHP has a server-setting called "register_globals", which is most likely set to OFF right now. When register_globals is ON, all variable scopes are made available in the "global" scope. In other words...all variables structures and their contents can be referenced by their name alone. In your case, you're trying to reference the variable named "Author." Since a form posted to your PHP script, using the GET method, the variable "Author" actually resides in the "$_GET" variable scope. When register_globals is set to OFF, than the only way you can reference the variable "Author", is through the $_GET scope. When register_globals is set to ON, you can simply reference the variable as "$Author"

If you use the POST method on your form, than you would reference $Author as $_POST['Author'], because it would be in the POST scope. Make sense?

climberfreak2003
09-08-2002, 12:19 PM
Thanks Griz. Im running my own web server so I just went into the php.ini file and found the register_globals option and turned it on. Now everything works fine.