HTML帖子表单不会发送输入值数据

时间:2017-09-03 12:19:38

标签: php html forms

这是我的表单html代码

<form id="register-form" action="submit.php" method="POST" style="display: block;">
    <h2>REGISTER</h2>
    <div class="form-group">
        <input type="text" name="fullname" id="fullname" tabindex="1" class="form-control" placeholder="Full Name">
    </div>
    <div class="form-group">
        <input type="text" name="username" id="username" tabindex="1" class="form-control" placeholder="Username">
    </div>
    <div class="form-group">
        <input type="email" name="email" id="email" tabindex="1" class="form-control" placeholder="Email Address">
    </div>
    <div class="form-group">
        <input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password">
    </div>
    <div class="form-group">
        <div class="row">
            <div class="col-sm-6 col-sm-offset-3">
                <input type="submit" name="register-submit" id="register-submit" tabindex="4" class="form-control btn btn-register" value="Sign Up Now">
            </div>
        </div>
    </div>
</form>

这是我的提交php

<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {
echo "there's a post submitted";

if(isset($_POST["username"]) && isset($_POST["email"]) && isset($_POST["password"]) && isset($_POST["password"])){
    require_once './DB_Functions.php';
    $db = new DB_Functions();

    // receiving the post params
    $name = $_POST['fullname'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $username = $_POST['username'];


    // create a new user
    $user = $db->storeUser($name, $email, $password, $username);
    if ($user) {
        // user stored successfully
        $_SESSION["uid"] = $user["unique_id"];
        $_SESSION["name"] = $user["name"];
        $_SESSION["email"] = $user["email"];
        $_SESSION["nickname"] = $user["nickname"];
        haeader("Location","details.php");
    } else {
        // user failed to store
        echo "Problem.";
    }

}
else {
    // in here i wantted to see which parameters are missing.
    echo ($_POST["username"]);
    echo ($_POST["fullname"]);
    echo ($_POST["email"]);
    echo ($_POST["password"]);
}
}
?>

这是来自submit.php的回复

  

已提交帖子   注意:未定义的索引:第32行的C:\ xxx \ submit.php中的用户名

     

注意:未定义的索引:第33行的C:\ xxx \ submit.php中的fullname

     

注意:未定义的索引:第34行的C:\ xxx \ submit.php中的电子邮件

     

注意:未定义的索引:第35行的C:\ xxx \ submit.php中的密码

为什么我无法从submit.php接收值?

2 个答案:

答案 0 :(得分:0)

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    echo "there's a post submitted";

    if (isset($_POST["username"]) && isset($_POST["email"]) && isset($_POST["password"]) && isset($_POST["password"])) {
        require_once './DB_Functions.php';
        $db = new DB_Functions();

        // receiving the post params
        $name = $_POST['fullname'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $username = $_POST['username'];


        // create a new user
        $user = $db->storeUser($name, $email, $password, $username);
        if ($user) {
            // user stored successfully
            $_SESSION["uid"] = $user["unique_id"];
            $_SESSION["name"] = $user["name"];
            $_SESSION["email"] = $user["email"];
            $_SESSION["nickname"] = $user["nickname"];
            haeader("Location", "details.php");
        } else {
            // user failed to store
            echo "sikinti";
        }
    } else {
        // in here i wantted to see which parameters are missing.

        /* this following code is expected to throw an error because of the conditions on the if statement above, so it doesn't exist.*/
        /*you may transfer this echos inside the if statement then you may change the logical operators to || to verify each parameters*/
        echo ($_POST["username"]);
        echo ($_POST["fullname"]);
        echo ($_POST["email"]);
        echo ($_POST["password"]);
    }
}

答案 1 :(得分:-1)