注册页面上的PHP错误:注意:未定义索引:在C:\ xampp \ htdocs \ Marcus \ signup.php中的第27行注册

时间:2018-11-17 07:42:05

标签: php

您好,我已经设置了我的“注册”页面,但收到此错误Notice: Undefined index: signup in C:\xampp\htdocs\Marcus\signup.php on line 27,该错误来自我的HTML,因为它使用$ _GET查看该URL,并查看其输入是否为错误。表单并显示错误消息,仅当您单击“注册”按钮并且错误消息和成功消息进入不同的HTML时,错误消息和成功消息才起作用,但是一旦其中一个错误出现,它就会消失远。任何帮助都将是巨大的!

我的注册页面使用HTML     

require "header.php";

 ?>

<main>
<h1 class="signup_text2">Signup</h1>
 <link rel="stylesheet" type="text/css" href="style.css">
 <?php


        if (isset($_GET['error'])) {
          if ($_GET['error'] == "emptyfields") {
            echo '<p class="error1"> Fill in all feilds!!</p>';
          }elseif ($_GET['error'] == "invaildmailuid") {
            echo '<p class="error2"> Invalid Username And Email! </p>';
          }elseif ($_GET['error'] == "invaliduid") {
            echo '<p class="error3"> Invalid Username </p>';
          }elseif ($_GET['error'] == "invalidmail") {
            echo '<p class="error4"> Invalid E-mail! </p>';
          }elseif ($_GET['error'] == "passswordcheck") {
            echo '<p class="error5"> Your Passwords do not match! </p>';
          }elseif ($_GET['error'] == "usertaken") {
            echo '<p class="error6"> Username is already taken! </p>';
          }
        }elseif ($_GET['signup'] == "success") {
          echo '<p class="success1"> Signup Successful!</p>';
        }
    ?>
<form action="includes/signup.inc.php" method="post">
    <input class="signup-Username" type="text" name="uid" placeholder="Username">
    <input class="signup-Email" type="text" name="mail" placeholder="E-mail">
    <input class="signup-Password" type="password" name="pwd" placeholder="Password">
    <input class="signup-Password2" type="password" name="pwd-repeat" placeholder="Repeat Password">
    <button class="signup_btn" type="sumbit" name="signup-submit">Signup</button>
</form>


</main>

PHP注册代码

<?php
if (isset($_POST['signup-submit'])) {

    require 'dbh.inc.php';


    $username = $_POST['uid'];
    $email = $_POST['mail'];
    $password = $_POST['pwd'];
    $passwordRepeat = $_POST['pwd-repeat'];

    if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
        header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
        exit();
    }elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
        header("Location: ../signup.php?error=invaildmailuid");
        exit();
    }elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        header("Location: ../signup.php?error=invaildmail&uid=".$username);
        exit();
    }elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
        header("Location: ../signup.php?error=invailduid&mail=".$email);
        exit();
    }elseif ($password !== $passwordRepeat) {
        header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
        exit(); 
    }else{
        $sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
        $stmt = mysqli_stmt_init($conn);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
            header("Location: ../signup.php?error=sqlerror1");
            exit();
        } else {
            mysqli_stmt_bind_param($stmt, "s", $username);
            mysqli_stmt_execute($stmt);
            mysqli_stmt_store_result($stmt);
            $resultCheck = mysqli_stmt_num_rows($stmt);
            if ($resultCheck > 0) {
                header("Location: ../signup.php?error=usertaken&mail=".$email);
                exit();
            } else {
                $sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?)";
                $stmt = mysqli_stmt_init($conn);
                if (!mysqli_stmt_prepare($stmt, $sql)) {
                    header("Location: ../signup.php?error=sqlerror");
                    exit();
                    } else {
                        $hashedPwd = password_hash($password, PASSWORD_DEFAULT);


                        mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
                        mysqli_stmt_execute($stmt);
                        header("Location: ../signup.php?signup=success");
                        exit();
                    }




            }


        }



    }
    mysqli_stmt_close($stmt);
    mysqli_close($conn);


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

}

0 个答案:

没有答案