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

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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法