<?php
    include_once "./connection.php";
    session_start();
    $conf = new DefaultDatabase();

    $configure = $conf->connect();

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

        $login = mysqli_query($configure,"SELECT COUNT(*) AS possible FROM admin where username = '".$username."' AND password = '".$password."'");

        $possible = mysqli_fetch_assoc($login);

        if($possible["possible"] < 1)
        {
            echo(
                "
                <script>
                    alert('Incorrect Username or Password');
                    window.location.href='../regional-admin/index.php';
                </script>
                "
            );
        }
        else
        {

            $_SESSION["admin"] = $username;
            header("location:../regional-admin/home.php");
        }
        
    }
?>