PHP Form Handling | GET and POST method PHP
- PHP Tutorial
- What is PHP
- Install PHP
- PHP Example
- PHP Echo
- PHP Print
- PHP Variables
- PHP $ and $$ Variables
- PHP Constants
- Magic Constants
- PHP Data Types
- PHP Operators
- PHP Comments
- PHP Boolean
- PHP is_bool() function
- PHP Integer
- PHP is_int() function
- PHP Float
- PHP is_float Function
- PHP Compound Types
- PHP Special Types
- PHP is_null() function
- PHP If Else
- PHP Switch
- PHP For Loop
- PHP While Loop
- PHP do while loop
- PHP Break
- PHP Functions
- PHP Parameterized Function
- PHP Call By Value
- PHP Call By Reference
- PHP Default Argument Values Function
- PHP Variable Length Argument Function
- PHP Recursive Function
- PHP Arrays
- PHP Indexed Array
- PHP Associative Array
- PHP Multidimensional Array
- PHP Array Functions
- PHP String
- PHP String Functions
- PHP Math functions
- PHP Form Handling | GET and POST method
- PHP Include File
- PHP Cookie
- PHP Session
- PHP File Handling
- PHP Open File
- PHP Read File
- PHP Write File
- PHP Append to File
- PHP Delete File
- PHP File Upload
- PHP Download File
- PHP Mail
- PHP MySQL Connect
- PHP MySQL Create Database
- PHP MySQL Create Table Example
- PHP MySQL Insert Record
- PHP Prepared Statements
- PHP MySQL Update Record
- PHP MySQL Delete Record
- PHP MySQL Select
- PHP MySQL Order By
- PHP Limit Data MySql
- PHP JSON
- PHP XML Parsers
- PHP SimpleXML Parser
- PHP SimpleXML - Get Node/Attribute Values
- PHP XML Expat Parser
- PHP XML DOM Parser
- PHP - AJAX intro
- MySQL CREATE VIEW
PHP Form Handling | GET and POST method
PHP Form Handling | GET and POST method
We can create and use forms in PHP. To get form data, we need to use PHP superglobals $_GET and $_POST.
The form request may be get or post. To retrieve data from get request, we need to use $_GET, for post request $_POST.
PHP Get Form
Get request is the default form request. The data passed through get request is visible on the URL browser so it is not secured. You can send limited amount of data through get request.
Let's see a simple example to receive data from get request in PHP.
File: form1.html
- <form action="welcome.php" method="get">
- Name: <input type="text" name="name"/>
- <input type="submit" value="visit"/>
- </form>
File: welcome.php
- <?php
- $name=$_GET["name"];//receiving name field value in $name variable
- echo "Welcome, $name";
- ?>
PHP Post Form
Post request is widely used to submit form that have large amount of data such as file upload, image upload, login form, registration form etc.
The data passed through post request is not visible on the URL browser so it is secured. You can send large amount of data through post request.
Let's see a simple example to receive data from post request in PHP.
File: form1.html
- <form action="login.php" method="post">
- <table>
- <tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>
- <tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>
- <tr><td colspan="2"><input type="submit" value="login"/> </td></tr>
- </table>
- </form>
File: login.php
- <?php
- $name=$_POST["name"];//receiving name field value in $name variable
- $password=$_POST["password"];//receiving password field value in $password variable
- echo "Welcome: $name, your password is: $password";
- ?>
Output: