Please enter your name:

 

This example was taken from

http://discomoose.org/2005/10/19/how-to-use-the-query-string-in-php/

 

The code for this form is:

<html>
<head>
<title>Test Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<form method="GET" action="page.php">
<p>Please enter your name:
<input type="text" name="username" />
<input type="submit" value="submit" />
</p>
</form>
</html>

 


The code for the PHP is:

 

<?
// uses test-form.html
// from http://discomoose.org/2005/10/19/how-to-use-the-query-string-in-php/

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


<table border="1" cellpadding="10">
<tr><th>variable</th> <th>value</th></tr>
<?
foreach($_GET as $variable => $value)
{
echo "<tr><td>" . $variable . "</td>";
echo "<td>" . $value . "</td>";
}

if ($_GET["username"] == "Rupert Russell") {
echo "Hello This is working";
}else{

echo "Your name is not Rupert Russell";

}

?>
</table>