<?php
session_start();
include 'koneksi.php';

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

$query = "SELECT * FROM tb_admin WHERE username='$username' AND password='$password'";

$result = mysqli_query($host, $query);

if (!$result) {
    die("Query Error: " . mysqli_error($host));
}

$cek = mysqli_num_rows($result);

if ($cek > 0) {
    $data = mysqli_fetch_assoc($result);

    if($data['status'] == "login_admin"){
        $_SESSION['username'] = $username;
        $_SESSION['login_admin'] = "admin";
        header('Location: dashboard_admin.php');
        exit;
    }else{
        echo "<script>alert('Username atau password salah'); window.location='halamanlogin.php';</script>";
        exit;
    }
}
?>
