PHP Form Handling

PHP Form Handling

In this chapter, we ‘ll discuss here forms in php. With the help of PHP superglobal variables $_GET, $_POST and $_REQUEST we can collect data from the user and apply operations according to our requirement like save data in the database, Print, Send mail etc.

Example Simple HTML Form

Index.html

<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
Contact No.: <input type="text" name="contact"><br>
<input type="submit">
</form>
</body>
</html>

When the user submits the above form with proper data. Form data is sent with the HTTP POST method for processing to a PHP file named “welcome.php”.

welcome.php

Welcome <?php echo $_POST["name"]; ?><br>
Your Contact No. is: <?php echo $_POST["contact"]; ?>

Output

Welcome Raj
Your Contact No. is: 978654321