使用表格收集数据 ( 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.
在这里,我们将学习如何通过HTML表单从用户那里获取数据,然后通过PHP程序对其进行处理并输出。 如果您有兴趣使PHP与SQL一起使用,则应访问本教程 ,如果您有兴趣通过电子邮件发送数据,则应访问本教程,因为本课程都不会涉及这两个概念。
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表单来收集一些数据。 这是一个例子:
Test Page
测试页
Data Collection
Data Collection
Name:
Age:
Name:
Age:
This page will send the Name and Age data to the page process.php
该页面会将名称和年龄数据发送到页面process.php
处理表格数据 ( Processing the Form Data )
Now lets create process.php to use the data from the HTML form we made:
现在让我们创建process.php以使用我们制作HTML表单中的数据:
";
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.
如您所知,如果省略了表单的method =“ post”部分,则显示数据的URL。 例如,如果您的名字是Bill Jones并且您已经35岁,那么我们的process.php页面将显示为http://yoursite.com/process.php?Name=Bill+Jones&Age=35如果需要,您可以手动更改URL的方式,输出将相应更改。
翻译自: https://www.thoughtco.com/processing-form-data-with-php-2693958