Home Tutorial Php Phpbeginners The $_POST Function


Share on Google+Share on Google+
The $_POST Function
Posted on: February 4, 2011 at 12:00 AM
This section contains the detail about the $_POST Function in PHP.

The $_POST Function

The $_POST function in PHP is used to gather data of form submit with method="post". When you send data using POST method, it is invisible to others and will not visible in browser. It has not limit of how much data you can send but by default it is set for 8 MB data transfer. You can change it by setting 'post_max_size' in the 'php.ini' file.

Given below example of how can you use it in a form :

<form action="registration.php" method="post">
Name: <input type="text" name="name" />
Address: <input type="text" name="address" />
<input type="submit" />

Fetching form data sent via POST method

You can fetch data of form as given below :

Name :<?php echo $_POST["name"]; ?><br />
Address : <?php echo $_POST["address"]; ?>

It will display the name and address which you have submitted in from.

$_REQUEST Method of PHP

The contents of both $_GET, $_POST, and $_COOKIE are contained by the PHP built-in $_REQUEST function. $_REQUEST Method is used to collect form data sent with both the GET and POST as follows :

Name : <?php echo $_REQUEST["name"]; ?><br />
Address :<?php echo $_REQUEST["address"]; ?>

The given below example will give you a clear idea how to use POST method :

Example :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<h3>Fill the Below Form :</h3>
<form action="PostMethod.php" method="post">
Name&nbsp&nbsp&nbsp&nbsp: <input type="text" name="name" /><br>
Address : <input type="text" name="address" /><br/>
<input type="submit" name="submit"/>

Your Name :<?php echo $_POST["name"]; ?>.<br />
Address :<?php echo $_POST["address"]; ?>

Output :

First, you need to fill up the form as :


When you press the submit button, it will show you the following :(you can see that address bar is not showing any send data)


Download Source Code


Related Tags for The $_POST Function:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 4, 2011

Recommend the tutorial

Advertisements Advertisements