Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The VeryTime,Stay informed and read the latest news today from The VeryTime, the definitive source.

How to Use a PHP Form to Collect User Data

9
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:

<html><head><title>Test Page</title></head><body><h2>Data Collection</h2><p><form action="process.php" method="post"><table><tr><td>Name:</td><td><input type="text" name="Name" /></td></tr><tr><td>Age:</td><td><input type="text" name="Age" /></td></tr><tr><td colspan="2" align="center"><input type="submit" /></td></tr></table></form></body></html>
This page will send the Name and Age data to the page process.php

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

<?phpprint "Your name is ". $Name;print "<br />";print "You are ". $Age . " years old";print "<br />";$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.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.