saftutorials.com
PHP Form Handling

Before learn form handling in PHP you should know about superglobals variable. In PHP these two superglobals variable which is used for collect data from the form.


How many Form Handling Method in PHP?
There are tow Form Handling method in PHP 1) $_GET and 2) $_POST


GET method has a restriction to data sent up to 1024 characters only but POST method does not have any restriction.

GET method produces a long string that appears in your server logs but does not appear in POST method.

Never use GET method if you have the password or other sensitive information want to sent to the server, you can use POST method at that time.

You can not use to send binary data, like images or word documents, to the server by using GET method but can use POST method at that time.


Example of simple HTML form by using post method

In this example, We use two input text box and one submit button.


<!DOCTYPE html>
<html>
<body>
<form action="home.php" method="post">
Name: <input type="text" name="name" value="John"><br>
Mobile: <input type="text" name="mobile" value="123456789"><br>
<input type="submit">
</form>
</body>
</html>


When the user fills the form and clicks on the submit button, the form data is sent to the home page by using HTTP POST method.

This is the home.php page which is mention in the action attribute


<!DOCTYPE html>
<html>
<body>
Hi <?php echo $_POST['name'];?>
Your mobile no is <?php echo $_POST['mobile'];?>
</body>
</html>

The above code produces the following results

Hi Johe

Your mobile no is 123456789


Example of simple HTML form by using get method

In this example, We use two input text box and one submit button.


<!DOCTYPE html>
<html>
<body>
<form action="home.php" method="get">
Name: <input type="text" name="name" value="John"><br>
Mobile: <input type="text" name="mobile" value="123456789"><br>
<input type="submit">
</form>
</body>
</html>


When the user fills the form and clicks on the submit button, the form data is sent to the home page by using HTTP GET method.

This is the home.php page which is mention in the action attribute


<!DOCTYPE html>
<html>
<body>
Hi <?php echo $_GET['name'];?>
Your mobile no is <?php echo $_GET['mobile'];?>
</body>
</html>

The above code produces the following results

Hi John

Your mobile no is 123456789


Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic