-1

I've searched for the answer to this, and from what I understand, I am missing a { or } somewhere. I keep reviewing my code, however, and I don't see that I have a curly bracket issue. What's going on? What I am trying to do is to get two different types of users accounts (admin, not admin).

<?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>';
    }
    }

?>

Heather
  • 13
  • 5
  • Where do you close: `if (password_verify($pass, $hash)) {` ? Go for a search. – Rizier123 May 01 '15 at 10:07
  • add one more closing bracket before catch – Let me see May 01 '15 at 10:08
  • @Letmesee Wait, let *him* see the missing bracket :) – Rizier123 May 01 '15 at 10:08
  • Thanks. I added the bracket and it works, but I still don't see it. Is there anything that I can do to make the seeing part easier? What I am doing now is looking at each phrase and confirming that it begins and ends with the curly bracket, sometimes working from the inside out. WIth so many brackets, however, there has got to be a better way. – Heather May 01 '15 at 10:15

1 Answers1

0

Looks to me like the following has no closing bracket:

if (password_verify($pass, $hash)) {
Kallum Tanton
  • 802
  • 7
  • 22
  • Thanks. I added the bracket and it works, but I still don't see it. Is there anything that I can do to make the seeing part easier? What I am doing now is looking at each phrase and confirming that it begins and ends with the curly bracket, sometimes working from the inside out. WIth so many brackets, however, there has got to be a better way. – Heather May 01 '15 at 10:15
  • Just indent every "if", "try...catch" and anything else that uses brackets. Your indentations get a little fuzzy towards the bottom of the above snippet. Some advanced editors like Adobe Dreamweaver and Visual Studio are good at managing indentations. – Kallum Tanton May 01 '15 at 10:16