<?php
include('../config/config.php');
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);

    // Check username and password directly in SQL
    $stmt = $conn->prepare("SELECT id, name FROM branches WHERE username = ? AND password = ?");
    $stmt->bind_param("ss", $username, $password);
    $stmt->execute();
    $result = $stmt->get_result();
    $branch = $result->fetch_assoc();
    $stmt->close();

    if ($branch) {
        $_SESSION['branch_id'] = $branch['id'];
        $_SESSION['branch_name'] = $branch['name'];

        header("Location: branch_dashboard.php");
        exit();
    } else {
        echo "Error: Invalid login credentials.";
    }
}
?>

