PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




POST Method in PHP


Tutorials »Php »

Topic

How to use POST method in PHP to get form values?



Explanation

Consider a simple form which contains a username, email address and a submit button.

A Simple Form:
Name:

Email:


When the user fill the form and click submit button the form will be submitted.

Coding to create a simple form

<form action="post.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="mail">
<input type="submit" value="Submit">
</form>

To use PHP POST method to get form values, you have to specify method = POST in the code.

Here POST method is used to access the form values. when submit button is clicked, the form data will be send to post.php file because this is the file name mentioned in the form action part.

Form is submitted when the user clicks the "Submit" button, when PHP POST method is used then the URL will not contain any form data, the URL will be passed as such. Here URL will be

http://www.hscripts.com/tutorials/php/post.php

In post.php file $_POST variable is used to collect values from a form.

Welcome echo $_POST["name"];
your Email echo $_POST["mail"];

RESULT:
Welcome Admin
your Email: Ad@hiox.com

OR

Assign the form data to a variable and make use of variable in the script. This is done in PHP using $_POST variable

$name=$_POST["name"];
$mail=$_POST["mail"];

Welcome: <?php echo $_GET["name"]; ?>
your Email: <?php echo $_GET["mail"];?>

RESULT:
Welcome:Admin
your Email: Ad@hiox.com






Other Links

web hosting