2017-08-30 9 views
-1

私はデータを入力した後にユーザーからデータを取得するフォームを持っていますが、これは達成されていません。私はどこに問題があるのか​​分からない。データのIキーの後空の文字列を受け取り続ける

//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(); 
} 
?> 
+3

'$のpw'する必要があります! = '$ pwd'、あなたは設定されていない変数をチェックします。 – Qirel

+0

また、変数に直接問合せを挿入するのではなく、prepared statementを使用する必要があります。 'mysqli_ *'はあなたが見ておくべき 'prepare()'と 'bind_param()'メソッドを提供します。 – Qirel

+0

サイドノート:パスワードに 'mysqli_real_escape_string()'は必要ありません。 –

答えて

4

ライン

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

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

これで私は正直に愚かに感じます。うん、それは問題だった。笑 – Minial

関連する問題