PHP Tutorial 6: Form Processing

form processing

The most important step in keeping visitors bounded to website and acquiring there feedback is forms on Webpage. This module also gives a dynamic look to the web application. Processing a form is very much easy in PHP.

The main reason for this is every form element in HTML can easily be integrated with PHP script. The <form> tag has all elements needed to process a form specially the text area and buttons.

The complete logic in processing forms in PHP can be explained with simplification as, you request input from the user, store it in a variable and process it. Processing may be displaying input on another page or storing it in Database.

The reliability PHP has with storing form inputs in variables is, variables in PHP do not require explicit declaration of type, that is what kind of data is to be stored in it. You can store string, number, character or any other data type PHP supports.

There are two built in functions that help you to handle form inputs.

1.      PHP $_GET
2.      PHP $_POST

Let us explain you this module with the help of example.

The below is HTML code which asks user for inputs. Save the script as form.html.


<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
From: <input type="text" name="from" />
You like to play: <input type="text" name="play" />
<input type="submit" />


Below is a PHP form  script. This code takes the input from the above form using $_POST method. The below code has to be saved as welcome.php. The reason is you can see <form action=”welcome.php”> in the above html code. It invokes welcome.php when you click the submit button. Care has to be taken, save both the files on same directory.

welcome.php :



echo "Your name is:\t".$name."<br>";
echo "Your are from:\t".$from."<br>";
echo "You play:\t".$play."<br>";
Thank you 

Here is the easy execution shots for you:
form processing

This is what after you click the submit button


If you need any further assistance do write to us in comments. We would be glad to reply.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top