继续接收空字符串

时间:2017-08-30 09:55:50

标签: php

我有一个从用户那里获取数据的表单,在键入数据之后,它们无法获得。我不确定问题出在哪里。

//Signup page 
<h2>SignUp</h2>

    <form class="signup-form" action="Cons/signup.conn.php" method="POST">

    <input type="text" name="firstName" placeholder="Name">
    <input type="password" name="userPassword" placeholder="Password">

    <button type ="submit" name = "submit" >Sign Up</button>
    </form>

在输入数据之后,我陷入了第一次验证,它调用了“标题(”位置:../ signup.php?signup = Empty“);”

//belongs to signup.conn.php ( where the process is done) 
<?php

    if (isset($_POST['submit'])) {
    include_once 'dbh-conn.php';

    $first = mysqli_real_escape_string($conn, $_POST['firstName']);
    $pw = mysqli_real_escape_string($conn, $_POST['userPassword']);

// ERROR handlers
// Check for EMPTY Fields;

if (empty($first) || empty($pwd)) {
    header("Location: ../signup.php?signup=Empty");
    exit();
 } else { 
      //does other validations
      if
 //Once everything is confirmed
 } else {
          // Hashing the password
                $hashedPwd = password_hash($pw, PASSWORD_DEFAULT);
                // insert Users into DB
                $sql = "INSERT INTO users (user_firstName,user_userPassword) 
                VALUES ('$first','$hashedPwd');";
                // ////////////////////////
                mysqli_query($conn, $sql);
                header("Location: ../signup.php?signup=success");
                exit();
            }
        }
    }
}
    header("Location: ../signup.php");
    exit();
}
?>

1 个答案:

答案 0 :(得分:4)

该行

if (empty($first) || empty($pwd)) {

应该是

if (empty($first) || empty($pw)) {