0

I'm new to PHP and stack, and I couldn't find anyone else having the same issue.

I'm trying to make a log in system with privileges for admins. One of the privileges is to be able to sign up more admins on the site.

When a user logs in via a log in form, I want it to check my database's admins table for the details first, and then check the users table if that search was unsuccessful.

I have done this in an includes file. I started off with only normal users, which worked fine and I have now tried to incorporate the admin functionality. and now it is returning the error:

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\project\includes\loginAdmin.inc.php on line 121

I have check the code and everything seems to close up fine,, database connection is fine, I can't seem to find anything wrong with the syntax. Am I being stupid and not seeing something obvious?

Here is the file returning the error:

<?php

session_start();

if (isset($_POST['submit'])) {

include 'dbh.inc.php';

$auid = mysqli_real_escape_string($conn, $_POST['uid']);
$apwd = mysqli_real_escape_string($conn, $_POST['pwd']);

//Error Handlers

//Check if inputs are empty

if (empty($auid) || empty($apwd)) {

    header("Location: ../index.php?login=error");
    exit();

} else {
    $sql = "SELECT * FROM admins WHERE admin_uid='$uid' OR admin_email='$uid'";
    $result = mysqli_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);

    if ($resultCheck < 1) {
        header("Location: ../index.php?login=error");
        exit();

    } else {

        if ($row = mysqli_fetch_assoc($result)) {

            //De-hashing password

            $hashedPwdCheck = password_verify($pwd, $row['admin_pwd']);

            if ($hashedPwdCheck == false){

                header("Location: ../index.php?login=error");
                exit();

            } elseif ($hashedPwdCheck == true) {

                //Log in the user

                $_SESSION['a_id'] = $row['admin_id'];
                $_SESSION['a_first'] = $row['admin_first'];
                $_SESSION['a_last'] = $row['admin_last'];
                $_SESSION['a_iemail'] = $row['admin_email'];
                $_SESSION['a_uid'] = $row['admin_uid'];

                header("Location: ../index.php?login=success");
                exit();
            }
        }
    }
}

} else {

if (isset($_POST['submit'])) {

include 'dbh.inc.php';

$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);

//Error Handlers

//Check if inputs are empty

if (empty($uid) || empty($pwd)) {

    header("Location: ../index.php?login=error");
    exit();

} else {
    $sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
    $result = mysqli_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);

    if ($resultCheck < 1) {
        header("Location: ../index.php?login=error");
        exit();

    } else {

        if ($row = mysqli_fetch_assoc($result)) {

            //De-hashing password

            $hashedPwdCheck = password_verify($pwd, $row['user_pwd']);

            if ($hashedPwdCheck == false){

                header("Location: ../index.php?login=error");
                exit();

            } elseif ($hashedPwdCheck == true) {

                //Log in the user

                $_SESSION['u_id'] = $row['user_id'];
                $_SESSION['u_first'] = $row['user_first'];
                $_SESSION['u_last'] = $row['user_last'];
                $_SESSION['u_iemail'] = $row['user_email'];
                $_SESSION['u_uid'] = $row['user_uid'];

                header("Location: ../index.php?login=success");
                exit();
            }
        }
    }
}

} else {

header("Location: ../index.php?login=error");
exit();
}

Thanks, sorry if this is an annoying noob error.

0 Answers0