用PHP处理表单数据

使用表格收集数据 ( 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值