我已经找到了答案,根据我的理解,我在某个地方错过了一个{或}。不过,我一直在检查我的代码,我没有看到我有一个大括号问题。这是怎么回事?我想要做的是获得两种不同类型的用户帐户(管理员,而不是管理员)。
<?php
include "header.html";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
include('include/db-connect.php');
$email = $_POST['email'];
$pass = $_POST['pass'];
try {
if (empty($email) ||
empty($pass))
throw new Exception('Enter all
fields.');
// we're good to go
// SELECT from db
$query = "SELECT * FROM users
WHERE email_address = '$email'";
$result = $con->query($query);
if (!$result)
throw new Exception("Login failed. Please try again.");
$row = $result->fetch_assoc();
$user_id = $row['user_id'];
$hash = $row['user_password'];
$email = $row['email_address'];
$first_name = $row['first_name'];
$user_is_admin = $row['user_is_admin'];
// check password
if (password_verify($pass, $hash)) {
session_start();
$_SESSION['email'] = $email;
$_SESSION['user_id'] = $user_id;
$_SESSION['first_name'] = $first_name;
$_SESSION['user_is_admin'] = $user_is_admin;
if($user_is_admin == TRUE){
echo "yes";
//header("location: admin-user-test.php"); // if user auth is 1, send to admin
}
else if($user_is_admin == FALSE){
echo "no";
//header("location: user-homepage-test.php"); // if user auth is 0, send to admin
}
else {
throw new Exception("Login failed here also. Please try again.");
}
}
catch (Exception $ex) {
echo '<div class="error">' . $ex->getMessage() . '</div>';
}
}
&GT;
答案 0 :(得分:0)
在我看来,下面没有结束括号:
if (password_verify($pass, $hash)) {