doulin2555 2017-11-11 21:19
浏览 20
已采纳

PHP注册表不工作[重复]

This question already has an answer here:

I am building this PHP login system to work on my skills. When the user signs up and their information is secured in the SQL database, I want to display signup.php?signup=success on top of my screen. When the user types in the information and something seems to be missing, I want it to display signup.php?signup=empty.

However, on my current page, even when I type in information, It keeps on displaying me signup.php?signup=empty. I know that my database is working for sure though....

Here is my PHP code for my signup.inc.php (included in an includes folder):

<?php

if (isset($_POST['submit'])) {

    include_once 'dbh.php';

    $first = mysqli_real_escape_string($conn, $_POST['first']);
    $last = mysqli_real_escape_string($conn, $_POST['last']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $uid = mysqli_real_escape_string($conn, $_POST['uid']);
    $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);

    //Error handlers
    //Check for empty fields
    if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
        header("Location: ../signup.php?signup=empty");
        exit();
    } else {
        //Check if input characters are valid
        if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
            header("Location: ../signup.php?signup=invalid");
            exit();
        } else {
            //Check if email is valid
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                header("Location: ../signup.php?signup=email");
                exit();
            } else {
                $sql = "SELECT * FROM users WHERE user_uid='$uid'";
                $result = mysqli_query($conn, $sql);
                $resultCheck = mysqli_num_rows($result);

                if ($resultCheck > 0) {
                    header("Location: ../signup.php?signup=usertaken");
                    exit();
                } else {
                    //Hashing the password
                    $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
                    //Insert the user into the database
                    $sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ('$first', '$last', '$email', '$uid', '$hashedPwd');";
                    mysqli_query($conn, $sql);
                    header("Location: ../signup.php?signup=success");
                    exit();
                }
            }
        }
    }

} else {
    header("Location: ../signup.php");
    exit();
}

Here is my signup.php form (I included header.php that has the database) :

<?php 

  include 'header.php';

?>

    <section class="main-container">
      <div class="main-wrapper">
         <h2>Signup</h2>
         <form class="signup-form" action="includes/signup.inc.php" method="POST">
           <input type="text" name="first" placeholder="First Name">
           <input type="text" name="last" placeholder="Last Name">
           <input type="text" name="email" placeholder="Email">
           <input type="text" name="uid" placeholder="Username">
           <input type="password" name="password" placeholder="password">
           <button type="submit" name="submit">Sign Up</button>
         </form>
      </div>
    </section>

    <?php

    include 'footer.php';

    ?>

What am i doing wrong here?

I appreciate all responses

</div>
  • 写回答

1条回答 默认 最新

  • douhuan1901 2017-11-11 21:21
    关注

    Simply change:

    <input type="password" name="password" placeholder="password">
    

    To:

    <input type="password" name="pwd" placeholder="password">
    

    Because in your php, you are using index pwd not password while from your html you are sending password not pwd

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!