Beginner Needs Help With HTTP Parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Buck Turgidson

    Beginner Needs Help With HTTP Parameters

    I am trying an example from an O'Reilly book that I just can't get to work.
    Can someone tell me where I am going wrong. According to the book, I should
    see the values of the HTTP request echoed by the PHP. But obviously they're
    not there. All I see is "regionName is wineType is"

    Any help would be appreciated.

    // index.html
    <HTML>
    <HEAD>
    <TITLE>Explor e Wines</TITLE>
    </HEAD>

    <BODY BGCOLOR="#fffff f">

    Explore all our <A
    HREF="example.5-4.php?regionNam e=All&amp;wineT ype=All">wines</A>

    <BR>
    Explore our <A HREF="example.5-4.php?regionNam e=All&amp;wineT ype=Red">red
    wines</A>

    <BR>
    Explore our <A
    HREF="example.5-4.php?regionNam e=Riverland&amp ;wineType=Red"> premium
    reds from the Riverland</A>

    <BR>
    </BODY>
    </HTML>


    // example.5-4.php
    <HTML>
    <HEAD>
    <TITLE>Paramete rs</TITLE>
    </HEAD>
    <BODY>
    <?php
    echo "regionName is $regionName\n";
    echo "wineType is $wineType\n";
    ?>
    </BODY>
    </HTML>


  • musicinmyhead

    #2
    Re: Beginner Needs Help With HTTP Parameters

    In order to get those variables from the URL, change the $regionName
    variable to $_GET['regionName'] and the $wineType to $_GET['wineType'].

    PHP expects those variables to be set somewhere else in the PHP file,
    so it doesn't know to look in the URL for the variable.

    Comment

    • Rick van Krevelen

      #3
      Re: Beginner Needs Help With HTTP Parameters

      > I am trying an example from an O'Reilly book that I just can't get to
      work.[color=blue]
      > Can someone tell me where I am going wrong. According to the book, I[/color]
      should[color=blue]
      > see the values of the HTTP request echoed by the PHP. But obviously[/color]
      they're[color=blue]
      > not there. All I see is "regionName is wineType is"[/color]

      In the early days, PHP made these variables available to use, from version 4
      and up however (I believe) they are typically stored in the global arrays
      $_GET or $_POST. To minimize the changes required for the O'Reilly examples
      to work, just type the following command at the top of your .php file:

      <? import_request_ variables("gP", "") ?>

      Also check out:

      PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.



      Comment

      • Buck Turgidson

        #4
        Re: Beginner Needs Help With HTTP Parameters

        > In order to get those variables from the URL, change the $regionName[color=blue]
        > variable to $_GET['regionName'] and the $wineType to $_GET['wineType'].
        >
        > PHP expects those variables to be set somewhere else in the PHP file,
        > so it doesn't know to look in the URL for the variable.[/color]


        Thanks to both! I guess my book is a bit dated, although it is March 2002.


        Comment

        Working...