
<?php
session_start();
include "koneksi.php";
if(isset($_POST['username'])) {
        $username = $_POST['username'];
        $password = md5($_POST['password']);
        
        $query = mysqli_query($koneksi, "SELECT * FROM users where username='$username' and password='$password'");

        if(mysqli_num_rows($query) > 0) {
            $data = mysqli_fetch_array($query);
            $_SESSION['users'] = $data;
            $_SESSION['username'] = $data = ['username'];
            echo '<script>location.href="index.php";</script>';
        } else {
            echo '<script>alert("Username atau Password tidak sesuai");</script>';
        }
    }
?>

<!DOCTYPE html>
<html lang="id">
    <style>
        body {
            background: linear-gradient(to bottom right, #A3D438, #004D40);
            /* height: 568px; */
        }
        .login {
            /* background-image: url('login/login.png'); */
            background-repeat: no-repeat;
            background-size: 300px 190px;
            background-position: center top;
            height: 568px;
        }
    </style>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Halaman: Login</title>
    </head>
    <body>

        <div class="login">
            <form action="" method="post">
            <table align="center">
                <tr>
                    <td colspan="2" align="center">
                        <h3>Login User</h3>
                    </td>
                </tr>
                <tr>

                    <td></td>
                    <td><input type="text" name="username" placeholder="Username" style="border: none"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="password" name="password" placeholder="Password" style="border: none"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button type="submit">Masuk</button>
                        <a href="daftar.php">Daftar</a>
                    </td>
                </tr>
            </table>
        </form>
        </div>
        

    </body>
</html>