|
-
Goldfish
script problems
I just started reading this book on php and im having trouble with one of its' examples. Here is the code:
FIRST PAGE
Code:
<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
Code:
<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.
Last edited by climberfreak2003; 09-08-2002 at 11:59 AM.
-
Ursus Arctos Moderatis
On your second page try this instead:
PHP Code:
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?
-
Goldfish
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|