为什么在访问其他 $_POST 元素之前检查 if isset($_POST['Submit']) ?

发布于 2024-10-29 15:01:14 字数 417 浏览 6 评论 0 原文

这段代码是做什么的?如果是 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'];

What is this code doing? If Isset, and what are the variables doing, whats the $_POST doing? Can someone explain please?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

堇年纸鸢 2024-11-05 15:01:14

$_POST 包含用户提交的表单中的数据。

if(isset($_POST['Submit']))

正在检查表单是否已提交。可能存在具有此名称的隐藏元素,或者创建提交按钮以包含此值。

其余行将*1 POST 超级全局信息复制到更易于使用的变量中。

(*1 并未实际复制,PHP 是写入时复制)

$_POST contains the data from the form the user submitted.

if(isset($_POST['Submit']))

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)

轮廓§ 2024-11-05 15:01:14

如果正在提交表单,则会分配变量。

If a form is being submitted, then it assigns variables.

混吃等死 2024-11-05 15:01:14

它将检查表单是否已提交,并将 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.

梦毁影碎の 2024-11-05 15:01:14

因此,这是尝试回答您的无定形问题。

if (isset($_POST['Submit']))

此行检查 $_POST 数组中是否存在名为“Submit”的条目。
isset 是一个检查 PHP 中变量是否存在的函数。

$_POST 是 PHP 中的一个 全局变量,用于捕获在 HTTP POST 请求中发送的键值对。在 99% 的用例中,$_POST 将包含 HTML 表单提交的结果。

$title=$_POST['title'];  

将 PHP 脚本中的 title 变量设置为 post 数组中的 title 字段。标题可能是表单提交的文本字段。

查看示例代码中 $_POST 的使用,对 php 脚本的请求可能来自如下所示的表单:

<form method="post" name="someForm" action="thatScript.php">
<input type="text" name="title"/>
<input type="text" name="forename"/>
<input type="text" name="surname"/>
... other inputs that correspond to $_POST entries...
<input type="submit" value="Submit" name="Submit"/> <!-- the submit field that is checked in the isset -->
</form>

注意:

这告诉浏览器在发布请求中提交表单的键值对。如果该行读取 那么浏览器将提交键值对作为 get 请求,并且 php 脚本将检查并使用 $_GET而不是 $_POST

So here is an attempt to answer your amorphous question.

if (isset($_POST['Submit']))

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.

$title=$_POST['title'];  

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:

<form method="post" name="someForm" action="thatScript.php">
<input type="text" name="title"/>
<input type="text" name="forename"/>
<input type="text" name="surname"/>
... other inputs that correspond to $_POST entries...
<input type="submit" value="Submit" name="Submit"/> <!-- the submit field that is checked in the isset -->
</form>

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.

ゃ懵逼小萝莉 2024-11-05 15:01:14

它检查表单是否已提交,如果为真,则将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文