script problems

Sharky Forums


Results 1 to 3 of 3

Thread: script problems

  1. #1
    Goldfish climberfreak2003's Avatar
    Join Date
    Jan 2002
    Location
    College Station, TX
    Posts
    85

    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.

  2. #2
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    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?

  3. #3
    Goldfish climberfreak2003's Avatar
    Join Date
    Jan 2002
    Location
    College Station, TX
    Posts
    85
    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
  •