PHP注册表格不起作用 [英] PHP Sign-up Form Not Working

查看:48
本文介绍了PHP注册表格不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建此PHP登录系统以使用我的技能.当用户注册并在SQL数据库中保护其信息安全时,我想在屏幕顶部显示signup.php?signup = success.当用户键入信息并且似乎缺少某些内容时,我希望它显示signup.php?signup = empty.

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.

但是,即使在我当前输入的页面上,即使我输入信息,它也会继续向我显示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....

这是我的signup.inc.php(包含在include文件夹中)的PHP代码:

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();
}

这是我的signup.php表单(我包括具有数据库的header.php):

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';

    ?>

我在这里做错什么了?

我感谢所有回复

推荐答案

只需更改:

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

收件人:

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

因为在您的php中,您使用的是索引 pwd 而不是 password ,而从html发送的是 password 而不是 pwd

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

这篇关于PHP注册表格不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆