为什么在访问其他 $_POST 元素之前检查 if isset($_POST['Submit']) ?
这段代码是做什么的?如果是 Isset,变量在做什么,那么 $_POST 在做什么?有人可以解释一下吗?
if (isset($_POST['Submit'])) {
$title=$_POST['title'];
$forename = $_POST['forename'];
$surname=$_POST ['surname'];
$dateofbirth=$_POST ['dateofbirth'];
$gender=$_POST ['gender'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$passcode1=$_POST ['passcode1'];
$passcode2=$_POST ['passcode2'];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
$_POST 包含用户提交的表单中的数据。
正在检查表单是否已提交。可能存在具有此名称的隐藏元素,或者创建提交按钮以包含此值。
其余行将*1 POST 超级全局信息复制到更易于使用的变量中。
(*1 并未实际复制,PHP 是写入时复制)
$_POST contains the data from the form the user submitted.
is checking to see if a form was submitted. There is likely a hidden element with this name, or the submit button was created to include this value.
The remainder of the lines copy*1 the information out of the POST super global into easier to use variables.
(*1 not actually copied, PHP is copy on write)
如果正在提交表单,则会分配变量。
If a form is being submitted, then it assigns variables.
它将检查表单是否已提交,并将 html 元素的值设置为 PHP 变量。
这些变量可用于进一步处理并随后存储在数据库中。
It will check If the form is submitted set the value of html elements in to the PHP variables that's it.
These variable can be used for further processing and later to store in database.
因此,这是尝试回答您的无定形问题。
此行检查 $_POST 数组中是否存在名为“Submit”的条目。
isset 是一个检查 PHP 中变量是否存在的函数。
$_POST
是 PHP 中的一个 全局变量,用于捕获在 HTTP POST 请求中发送的键值对。在 99% 的用例中,$_POST
将包含 HTML 表单提交的结果。将 PHP 脚本中的 title 变量设置为 post 数组中的 title 字段。标题可能是表单提交的文本字段。
查看示例代码中 $_POST 的使用,对 php 脚本的请求可能来自如下所示的表单:
注意:
So here is an attempt to answer your amorphous question.
This line is checking to see if an entry called 'Submit' is present in the $_POST array.
isset is a function that checks the existence of variables in PHP.
$_POST
is a global variable in PHP that captures the key-value pairs sent in an HTTP POST request.$_POST
will contain the result of an HTML form submission in 99% of the use cases.is setting the title variable in the PHP script to the title field in the post array. title was probably a text field submitted by a form.
Looking at the use of $_POST in your example code, the request to the php script probably comes from a form that looks like:
Notice:
<form method="post"
This tells the browse to submit the key-value pairs for the form in a post request. If that line read
<form metho="get"
then the browse would submit the key-value pairs as a get request and the php script would check and use$_GET
instead of$_POST
.它检查表单是否已提交,如果为真,则将 post 数组(由发送页面发送)中的值分配给变量。
例如,此
$_POST['title']
的值分配给变量$title
。It checks if the form has been submitted and if its true then values from post array (that are sent by the sending page) are assigned to variables.
for example value for this
$_POST['title']
is assigned to variable$title
.