How to use the query string in PHP

Passing query strings

As a link

<a href="page.php?username=indika">Indika</a>

HTML Forms

<form method="get" action="page.php"> 
Please enter your name:
 
<input name="username" />
 
<input type="submit" />
 
</form>

Receiving query strings

if($_GET['username'] == "")
 
{
 
    // no username entered
 
    echo "You did not enter a name.";
 
}
 
else
 
{
 
    echo "Hello, " . $_GET['username'];
 
}

Recieving all quesry strings passed

foreach($_GET as $variable =&gt; $value)
 
{
 
    echo $variable . " =  ". $value ;
 
}

Leave a Reply

You must be logged in to post a comment.