NYCPHP Meetup

NYPHP.org

What is $QUERY_STRING ?

Matthew Zimmerman mz34 at nyu.edu
Tue Mar 11 11:09:01 EST 2003


Ok, this may sound like a really naive question, but I will ask anyway.

What is the predefined variable $QUERY_STRING ? The PHP manual says:

'QUERY_STRING'
The query string, if any, via which the page was accessed.

That definition is a bit tautological:) I ask because I have some code 
I grabed from a website and it contains the line:

<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". 
$QUERY_STRING;}?>"method="POST">

I am guessing this means if the form has been submitted, the key/value 
pairs will be contained in a variable called $QUERY_STRING, but maybe I 
am way off there?

Just to test I made a simple form:

<form action="test2.php" method="post">

Name<input type="text" name="name">
Address<input type="text" name="address" >
Title<input type="text" name="title" >
<input type="submit" name="Submit"">
</form>

I sent that to

<?php

$x= $_POST[name];
$y= $_POST[address];
$z= $_POST[title];

print ("$x ");
print ("$y ");
print ("$z ");
print ($QUERY_STRING);
?>

But nothing prints out for $QUERY_STRING. I tired both POST and GET.

Thanks! I am asking this question mostly out of curiosity. The code I 
downloaded works fine. I just want to know why it works.

Matt




More information about the talk mailing list