Processing Form Data With PHP

of 02

Using a Form to Collect Data

Here we are going to learn how to take data from the user through an HTML form and then process it through a PHP program and output it. If you are interested in making PHP work with SQL you should visit this tutorial and if you are interested in sending data via email you should visit this tutorial as neither concepts will be covered in this lesson.

For this tutorial you will need to create two pages. On the first page we will create a simple HTML form to collect some data. Here is an example:


Test Page

Data Collection


This page will send the Name and Age data to the page process.php

of 02

Processing the Form Data

Now lets create process.php to use the data from the HTML form we made:

print "You are ". $Age . " years old";
print "
"; $old = 25 + $Age; print "In 25 years you will be " . $old . " years old"; ?>

As you may be aware, if you leave out the method="post" part of the form, the URL with show the data. For example if your name is Bill Jones and you are 35 years old, our process.php page will display as If you want, you can manually change the URL in this way and the output will change accordingly.

mla apa chicago
Your Citation
Bradley, Angela. "Processing Form Data With PHP." ThoughtCo, Jan. 29, 2020, Bradley, Angela. (2020, January 29). Processing Form Data With PHP. Retrieved from Bradley, Angela. "Processing Form Data With PHP." ThoughtCo. (accessed January 28, 2021).