Free WebSchools.com

Google




Blog ForumsLive chat WebhostingLink TO UsSEO ToolsResources


HOME

PHP Introduction
Php Installation
PHP Basic Scripts
PHP variables
PHP operators
PHP Conditional statement
PHP functions
PHP Arrays

PHP Objects & classes
PHP with Forms
PHP Files
PHP With Database
PHP session
PHP cookies
PHP Regular Expressions
PHP Server Environment
PHP Graphics
PHP Advance

PHP Form Handling



The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.



Form example:


The example HTML page above contains three input fields and a submit button. When the user fills in this form and click on the submit button, the form data is sent to the "test.php" file.
The "test.php" file looks like this:



A sample output of the above script may be:
you have given the information as
NAME hari
ADDRESS 4131 s 200 w
PHONE NUMBERS 802-222-222


The $_GET Variable

The $_GET variable is an array of variable names and values sent by the HTTP GET method.
The $_GET variable is used to collect values from a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and it has limits on the amount of information to send (max. 100 characters).Here is the example



When the user clicks the "Submit" button, the URL sent could look something like this:

http://www.freewebschools.com/test.php?name=hari&phone=801-111-111

The $_POST Variable

The $_POST variable is an array of variable names and values sent by the HTTP POST method.
The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.


Example


When the user clicks the "Submit" button, the URL will not contain any form data, and will look something like this:

http://www.webschools.com/test.php

The "test.php" file can now use the $_POST variable to catch the form data (notice that the names of the form fields will automatically be the ID keys in the $_POST array):


If we use POST method in our forms
Variables sent with HTTP POST are not shown in the URL
Variables have no length limit as GET method has limit(max 100)