数据库为空

时间:2019-02-06 17:55:08

标签: php database

我的数据库为空。我不知道怎么了这是语法错误吗?我已经尝试找到一种语法错误,但是找不到。谁能帮我或告诉我什么问题?

<?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=invalidmail&uid=");
          exit();
      }
      elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        header("Location: ../signup.php? 
        error=invalidmail&uid=".$username);
        exit();
      }
      elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
        header("Location: ../signup.php?error=invalidmail&uid=".$email);
        exit();
      }
      elseif ($password !== $passwordRepeat) {
        header("Location: ../signup.php? 
        error=passworcheck&uid=".$username."&mail=".$email);
      }
      else {

       $sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
       $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, "ssss", $username, $email, 
          $password);
          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 :(得分:0)

我的猜测:这行是错误的:

$sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
                                         ^^^^^^^^^
....
mysqli_stmt_bind_param($stmt, "s", $username);

我想,您想问一个用户名以获取用户ID。

可能还有更多错误。