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

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $username = mysqli_real_escape_string($conn, $_POST['username']);
    $password = mysqli_real_escape_string($conn, $_POST['password']);

    // Query untuk mengecek username dan password
    $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
    $result = mysqli_query($conn, $query);

    if (mysqli_num_rows($result) == 1) {
        // Jika login berhasil
        $_SESSION['username'] = $username;
        header("Location: index.php");
        exit();
    } else {
        // Jika login gagal
        echo "<script>alert('Username atau password salah');window.location='login.php';</script>";
    }
}
?>
