<?php
session_start();
include ("db.php");
if($_SERVER['REQUEST_METHOD'] !== 'POST'){
    header("Location: index.php");
    exit;
}

if(empty($_POST['username']) || empty($_POST['password'])){
    header("Location: index.php?Empty=Empty username or password");
    exit;
}

$username = $_POST['username'];
$password = $_POST['password'];
$query = mysqli_query($conn, "SELECT * FROM admin WHERE username = '$username' ");
$pass = $query ? mysqli_fetch_assoc($query) : null;

if($pass && $pass['password'] === $password) {
    $_SESSION['User'] = $pass['username'];
    header("Location: dashboard.php");
    exit;
}else{
    header("Location: index.php?Invalid=Wrong username or password");
    exit;
}
?>
