[nycphp-talk] What is $QUERY_STRING ?

David Sklar sklar at
Tue Mar 11 11:26:11 EST 2003

$QUERY_STRING is the stuff after the "?" in a GET URL:

$QUERY_STRING (or $_SERVER['QUERY_STRING']) is "item=cereal&quantity=56".

It doesn't have to be key/value pairs:

$QUERY_STRING is "buy".

You didn't see it in the form you used below because the method was POST.
Change it to GET and watch the query string bloom.


On Tuesday, March 11, 2003 11:09 AM, Matthew Zimmerman wrote:

> 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:
> 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