为什么我的表单变量没有通过POST


Why are my form variables not passing through POST?

我通过POST发送表单数据,但没有设置相应的POST变量,也没有设置。

此外,当我将POST数据存储到本地PHP变量中时,我似乎无法使用这些变量。(一旦我解决了第一个问题,我就有一种感觉,我也可以使用变量了。)

第二页(见下文)输出的错误消息是:

Notice: Undefined variable: postUsername in (...somepath)'scripts'create-member.php on line 10

(表单页):

<form action="scripts/create-member.php" method="POST">
        <input type="text" name"username" value="" placeholder="User Name"> <br />
        <input type="password" name"password" value="" placeholder="Password"> <br />
        <input type="password" name"passwordConfirm" value="" placeholder="Confirm Password"> <br />
        <!-- ?type email or type text -->
        <input type="email" name"email" value="" placeholder="Email" autofocus> <br />
        <input type="submit" name="submitRegistration" value="Register!">
    </form>

(第二页)scripts''create-member.hp:

<?php
//!proper way to declare variables obtained from POST.
// Data from form "register.php"
if ( isset($_POST['username']) ) {
    $postUsername = $_POST['username'];
}

echo $postUsername;    // <-- this is line 10

?>

我也尝试过将isset()用于提交按钮,但这并没有解决问题。我在这里简化了很多代码,并对其进行了测试。

在您的html代码中,您错过了name=

name="username"

代替name"username"


这是您的固定代码。

<input type="text" name="username" value="" placeholder="User Name"> <br />
<input type="password" name="password" value="" placeholder="Password"> <br />
<input type="password" name="passwordConfirm" value="" placeholder="Confirm Password"> <br />
<!-- ?type email or type text -->
<input type="email" name="email" value="" placeholder="Email" autofocus> <br />

问题不在register.php

你可以试着这样写:

if ( isset($_POST['username']) ) {
$postUsername = $_POST['username'];
echo $postUsername;
}

我在发布到文件夹中的index.php文件时遇到了类似的问题。

<form id="register" name="register" method="POST" action="/register">
// BROKEN

所有$_POST变量都是空的,直到我在表单操作后中添加了一个尾随的正斜杠

<form id="register" name="register" method="POST" action="/register/">
// WORKS