解析错误:语法错误,意外的'else'(T_ELSE),期望文件结尾,错误在哪里?

时间:2019-04-27 21:18:45

标签: php

我想用php和html创建一个登录表单。但是一个php文件中有一个错误。

我正在XAMPP上运行数据库,并在PC上离线进行测试。

运行此代码时,出现以下错误消息: “解析错误:语法错误,意外的'else'(T_ELSE),预计第54行的***中的文件结尾。“

这是第54行结尾:

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

这是完整的代码:

<?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();
  } 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 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_results($stmt);
    $resultCheck  = myssqli_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();
        }

那么错误在哪里?我认为我正确地关闭了所有内容。

0 个答案:

没有答案