<?php
session_start();
include $_SERVER['DOCUMENT_ROOT']."/pon_pes_nurul_iman/koneksi.php";

$username = $_POST['username'];
$password = md5($_POST['password']);

$query = mysqli_query($conn, "SELECT * FROM user WHERE username='$username' AND password='$password'");
$data = mysqli_fetch_assoc($query);

if ($data) {
    $_SESSION['login'] = true;
    $_SESSION['username'] = $data['username']; // ⬅ INI PENTING
    $_SESSION['role'] = $data['role'];

    header("Location: admin/dashboard.php");
    exit;
} else {
    echo "<script>alert('Login gagal'); window.location='login.php';</script>";
}
