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

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

$result = $conn->query("SELECT * FROM users WHERE email='$email' AND password='$password'");

if($row = $result->fetch_assoc()){
    $_SESSION['login'] = true;
    $_SESSION['role'] = $row['role'];
    $_SESSION['email'] = $row['email'];

    if($row['role'] == 'admin'){
        header("Location: ../admin/index.php");
    } else {
        header("Location: ../dashboard/index.php");
    }
} else {
    echo "Login gagal";
}
?>