为什么我的PHP登录系统中总是出现错误500

时间:2019-02-28 10:59:53

标签: php mysqli

下面是我为登录系统键入的代码。单击提交注册按钮时,我始终收到错误500。据我所知,我没有任何语法错误。我绝对不知道我做错了什么,并希望你们的建议。

出于隐私原因,我删除了$ dBUsername和$ dBPassword,抱歉:(

连接到数据库的代码: 后端/dbh.be.php

<?php

    $servername = "localhost":
    $dBUsername = "";
    $dBPassword = "";
    $dBName = "admhap_Users";

    $conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);

    if(!$conn) {
      die("Connection failed: ".mysqli_connect_error());
    }

我的注册页面,即您在网站上看到的页面: signup.php

<?php
  require "header.php";
?>

    <main>
      <div>
        <section>
          <h1>Aanmelden</h1>
          <form action="back-end/signup.be.php" method="post">
            <input type="text" name="uid" placeholder="Gebruikersnaam...">
            <input type="text" name="mail" placeholder="E-mail...">
            <input type="password" name="ww" placeholder="Wachtwoord...">
            <input type="password" name="ww-her" placeholder="Herhaal wachtwoord...">
            <button type="submit" name="signup-submit">Aanmelden</button>
          </form>
        </section>
      </div>
    </main>

<?php 
  require "footer.php";
?>

我的sigup页背后的后端代码: 后端/signup.be.php

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

  require 'dbh.be.php'; 

        $username = $_POST['uid'];
    $email = $_POST['mail'];
    $password = $_POST['ww'];
    $passwordRepeat = $_POST['ww-her'];


    if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {      
        header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
        exit();
    }
    else if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
        header("Location: ../signup.php?error=invalidmailuid");
        exit();
    }
    else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        header("Location: ../signup.php?error=invalidmail&uid=".$username);
        exit();     
    }
    else if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
        header("Location: ../signup.php?error=invaliduid&mail=".$email);
        exit();
    }
    else if ($password !== $passwordRepeat) {
        header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
        exit();
    }
    else {

        $sql = "SELECT gebruikersnaam FROM gebruikers WHERE gebruikersnaam=?";
        $stmt = mysqli_stmt_init($conn);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
            header("Location: ../signup.php?error=sqlerror");
        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=succes");
                    exit();
                }

            }
        }

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

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

已经非常感谢

1 个答案:

答案 0 :(得分:1)

从以下文件中检查代码:back-end / dbh.be.php 在第一行

$ servername =“ localhost”:

您使用:而不是;来终止行,这是按下提交按钮后立即得到ERROR 500的主要原因。