articles

Home / DeveloperSection / Articles / PHP $_POST Function

PHP $_POST Function

Anonymous User7668 09-Sep-2011

The built-in $_POST function is used to collect values from a form sent with method="post". Information sent from a form with the POST method is invisible to others and has limits up to 8mb amount of information to send.

Let’s we have an example, how to collect information from form with the help ‘post’ method.

Example:
<html>
  <head>
       <title> Post Methods</title>
  </head>
  <body>
              <form action="PostExampleOutput.php" method="POST">
              <table>
              <tr>
              <td>Name: </td>
              <td><input type="text"  name ="uname"/>
              <td>
              </tr>
              <tr>
                           <td>Age : </td>
                           <td><input type="text"  name="age"/> </td>
              </tr>
                     <tr>
                     <td></td>
              <td><input type="submit"  value="Submit"/> </td>
              </tr>
              </table>
              </form>
  </body>
 
</html>

 

Now when user click on ‘Submit’ button, the URL send to the server will look like this:

http://localhost:85/MySiteFile/PostExampleOutput.php

The ‘PostExampleOutput.php’ page will contain the following code.

<html>
  <head>
       <title>Post Methods</title>
      
  </head>
  <body>
       <?php
              echo "Welcome :".$_POST['uname']."</br>";
              echo "you are ". $_POST['age']."years old";
        ?>   
             
  </body>
 
</html>
Output:

PHP $_POST Function

Now fill the entire field and click on ‘Submit’ button.

PHP $_POST Function

$_Request Function:

In PHP, There is a built function ‘$_Request’, which is used for collect the information from form either it is used ‘GET’ method for submitting form or ‘POST’ method.  

Let’s we have an example, how to used $_Request function in PHP.

Example: Use $_Request function when form use ‘POST’ method.
<html>
  <head>
       <title> Request Methods</title>
  </head>
  <body>
              <form action="PostExampleOutput.php" method="POST">
              <table>
              <tr>
              <td>Name: </td>
              <td><input type="text"  name ="uname"/>
              <td>
              </tr>
              <tr>
                      <td>Age :</td>
                      <td><input type="text" name="age"/> </td>
              </tr>
                     <tr>
                     <td></td>
              <td><input type="submit"value="Submit"/> </td>
              </tr>
              </table>
              </form>
  </body>
 
</html>

 

The ‘RequestExampleOutput.php’ page will contain the following code.

 

<html>
  <head>
       <title>Request Methods</title>
      
  </head>
  <body>
       <?php
                echo "Welcome :".$_REQUEST['uname']."</br>";
                echo "you are ". $_REQUEST['age']."years old";
        ?>   
             
  </body>
 
</html>

 

Output:

PHP $_POST Function

Now fill the entire field and click on ‘Submit’ button.

PHP $_POST Function



Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By