View Single Post

  #3 (permalink)  
Old 12-06-2003
wedger
 
Posts: n/a
Default Re: newbie querystring variables

Kelly Soden wrote:

> I am new to PHP and am having problems using variables passed in a
> querystring. For example:
>
> <html>
> <head>
> <title>submit-vars.html</title>
> <body>
> <a href="http://localhost/print-vars.php?id=1"> test</a>
> </body>
> </html>
>
> <html>
> <head>
> <title>print-vars.php</title>
> </head>
> <body>
> <p>The query string is: <?php echo $_SERVER['QUERY_STRING']; ?></p>
> <p><? echo $_GET['id'] ?></p>
> <?php printf("\n</br>print variable here->%s",$id); ?>
> </body>
> </html>
>
> Clicking on the link in submit-vars.html calls print-vars.php producing
> the following html source:
>
> <html>
> <head>
> <title>print-vars.php</title>
> </head>
> <body>
> <p>The query string is: id=test</p>
> <p>test</p>
>
> </br>print variable here-></body>
> </html>
>
>
> From the tutorials I have read, it is my understanding that PHP
> automatically create a variable when it sees a name=value pair in a
> querystring. Therefore I would expect the word "test" to again be printed
> after "print variable here->". The behavior is the same if I submit the
> querystring using a form instead of embedding it in a link. The simple
> PHP
> scripts I have written seem to work fine except for this. What am I
> missing?
>
> My configuration is as follows:
> Apache/1.3.28 (Win32), PHP/4.3.4, on Win 2K.
>
> Apache is running in a command shell, not as a service. I have PHP
> loading as a DSO, not as CGI, and have added the following lines in my
> httpd.conf:
>
> LoadModule php4_module "c:/php/sapi/php4apache.dll"
> AddType application/x-httpd-php .php
>
> Thanks!
> -Kelly



In my setup, I get the following source code (as expected):
--
<html>
<head>
<title>print-vars.php</title>
</head>
<body>
<p>The query string is: id=1</p>
<p>1</p>

</br>print variable here->1</body>
</html>
--

The line:
printf("\n</br>print variable here->%s",$id);
prints the variable $id, which has the value '1' (set as a GET-variable in
the link on the first page).

Test is just the linked text on the first page, and does not get passed on
to the second page.

If you wanted the value 'test' transferred, you should have written:
<a href="http://localhost/print-vars.php?id=test">test</a>
Reply With Quote