Form Handling: Collecting  Data at Server 

  $_GET , $_POST and  $_REQUEST are PHP superglobals ,used to collect form-data at server.

 The GET Method

The GET method sends the encoded user information appended to the page request (QueryString). The page and the encoded information are separated by the ? character. like this

           test.php?txtName=shailesh&txtMessage=Hello+Sir&submit=Submit

Here is an example to accept user's data by GET Method

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>codeTpoint.com</title>
</head>
<body>

<?php
 if( isset($_GET["submit"]))
 {
      if( $_GET["txtName"] &&  $_GET["txtMessage"] )
  	{
		$n=$_GET["txtName"];
		$m=$_GET["txtMessage"];
		echo $m."is sucessfully submitted by".$n;
	}
	else
	{
		echo "Empty Field(s)"; 
	}
  }

?>

 <center>
 <form  action="<?php $_PHP_SELF ?>" method="get">
 <br/> Enter  Name    <input type="text" name="txtName" />
 <br/> Enter Message <input  type="text" name="txtMessage" />
 <br />
 <input type="submit"  name="submit" />
 </form>	
 <center/>

</body>
</html>

The POST Method

The POST method transfers information via HTTP headers.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

<?php

 if( isset($_POST["submit"]))
 {
      if( $_POST["txtName"] &&  $_POST["txtMessage"] )
  	{
		$n=$_POST["txtName"];
		$m=$_POST["txtMessage"];
		echo $m."is sucessfully submitted by".$n;
		
		
	}
	else
	{
		echo "Empty Field(s)"; 
	}
  }
  
?>

<center>
 <form  action="<?php $_PHP_SELF ?>" method="post">
 <br/> Enter  Name    <input type="text" name="txtName" />
 <br/> Enter Message <input  type="text" name="txtMessage" />
 <br />
 <input type="submit"  name="submit" />
 </form>	
 <center/>
 </body>
</html>

The $_REQUEST variable

The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

if( isset($_POST["submit"]))
 {
      if( $_REQUEST["txtName"] &&  $_REQUEST["txtMessage"] )
  	{
		$n=$_REQUEST["txtName"];
		$m=$_REQUEST["txtMessage"];
		echo $m."is sucessfully submitted by".$n;
	
	}
	else
	{
		echo "Empty Field(s)"; 
	}
  }
  

?>
 
 <center>
 <form  action="<?php $_PHP_SELF ?>" method="post">
 <br/> Enter  Name    <input type="text" name="txtName" />
 <br/> Enter Message <input  type="text" name="txtMessage" />
 <br />
 <input type="submit"  name="submit" />
 </form>	
<center/>

</body>
</html>