<?php
include 'db-connection.php';
session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];

// Retrieve the user's username and password from the database
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$sql = "SELECT * FROM employee_accounts WHERE username = '$username' AND password = '$password'";

$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);

if(!empty($row)) {
    $_SESSION['username'] = $row["username"];        
    $_SESSION['password'] = $row["password"];
    $_SESSION['fname'] = $row["first_name"];
    $_SESSION['lname'] = $row["last_name"];
    $_SESSION['email'] = $row["email"];

    // Redirect to Dashboard if Login is Successful
    header("location: ../dashboard.php");
} else {
    // Redirect to Error Page
    header("location: ../pages-login-employee.php?error");
    exit();
}
?>