<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Database connection
  include('connection.php');

    $username = $_POST["username"];
    $password = $_POST["password"];

    // Prepare and execute the SQL query
    $sql = "SELECT username, password FROM admin_login WHERE username = '$username' AND password = '$password'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        // User found, create a session
        $_SESSION["username"] = $username;
        // echo 'ok';
        // header("Location: index.php"); // Redirect to the dashboard page
        
  header("Location: index.php?success= Login Successfully!!!");
  exit(); 
    } else {
        echo "Invalid username or password.";
    }

    $conn->close();
}
?>