Processing Form Data With PHP

01
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

 

Name:Age:

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

02
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 http://yoursite.com/process.php?Name=Bill+Jones&Age=35 If you want, you can manually change the URL in this way and the output will change accordingly.

Format
mla apa chicago
Your Citation
Bradley, Angela. "Processing Form Data With PHP." ThoughtCo, Jun. 15, 2017, thoughtco.com/processing-form-data-with-php-2693958. Bradley, Angela. (2017, June 15). Processing Form Data With PHP. Retrieved from https://www.thoughtco.com/processing-form-data-with-php-2693958 Bradley, Angela. "Processing Form Data With PHP." ThoughtCo. https://www.thoughtco.com/processing-form-data-with-php-2693958 (accessed May 21, 2018).