
<?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-color: rgb(24, 24, 24);
        }
        .login {
            /* background-image: url('login/login.png'); */
            height: 568px;
            margin-top: 0;
            background-image: url("login/log.png");
            background-size: 50% 80%;
            background-position: center;
            background-repeat: no-repeat;
        }
        h3 {
            color: white;
        }
        table {
            padding: 42px;
            font-size: 50px;
        }
        a {
            color: white;
            font-size: 21px;
        }
        input {
            color: white;
            background-color: rgb(24, 24, 24);
        }
    </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">
                        <div id="h3">
                            <h3>Login User</h3>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td align="center"><input type="text" name="username" placeholder="Username" style="border: none"></td>
                </tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr>
                    <td></td>
                    <td align="center"><input type="password" name="password" placeholder="Password" style="border: none"></td>
                    <!-- <td><input type="password" name="password" placeholder="Password" style="border: none"></td> -->
                </tr>
                <tr>
                    <td></td>
                    <td align="center">
                        <button type="submit">Masuk</button>
                        <a href="daftar.php">Daftar</a>
                    </td>
                </tr>
            </table>
        </form>
        </div>
        

    </body>
</html>