<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Memeriksa apakah elemen $_POST ada sebelum mengaksesnya
    if (isset($_POST["email"]) && isset($_POST["password"])) {
        $email = $_POST["email"];
        $password = $_POST["password"];

        // Koneksi ke database
        $servername = "localhost";
        $database = "borneom2_percobaan";
        $username = "borneom2_borneo";
        $db_password = "borneom2_borneo";

        $conn = mysqli_connect($servername, $username, $db_password, $database);

        if (!$conn) {
            die("Koneksi Gagal: " . mysqli_connect_error());
        }

        // Query untuk memeriksa informasi masuk
        $sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
        $result = mysqli_query($conn, $sql);


        if (mysqli_num_rows($result) == 1) {
            // Informasi masuk benar
            echo "Login berhasil! Selamat datang, $email!";
        } else {
            // Informasi masuk salah
            echo "Login gagal. Email atau kata sandi salah.";
        }

        mysqli_close($conn);
    }else {
        echo "Login gagal. Email atau kata sandi salah.";
    }
} else {
    echo "Akses tidak valid";
}
?>