Connecting Tech Pros Worldwide Help | Site Map

Beginner Needs Help With HTTP Parameters

Buck Turgidson
Guest
 
Posts: n/a
#1: Jul 17 '05
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>Explore Wines</TITLE>
</HEAD>

<BODY BGCOLOR="#ffffff">

Explore all our <A
HREF="example.5-4.php?regionName=All&amp;wineType=All">wines</A>

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

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

<BR>
</BODY>
</HTML>


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


musicinmyhead
Guest
 
Posts: n/a
#2: Jul 17 '05

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.

Rick van Krevelen
Guest
 
Posts: n/a
#3: Jul 17 '05

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:

http://php.net/manual/en/function.im...-variables.php


Buck Turgidson
Guest
 
Posts: n/a
#4: Jul 17 '05

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.


Closed Thread