<?php
session_start();
include "koneksi.php";
?>

<!DOCTYPE html>
<html lang="en">
<style>
    body {
            height: 568px;
            rgb(24, 24, 24)
        }
    div {
            border-radius: 7px;
            justify-content: center;
            justify-self: center;
            width: 540px;
            height: 280px;
            background-image: url("succes/loginSuccess.png");
            background-size: 100% 100%;
            background-position: center;
            background-repeat: no-repeat;
    }
    h3 {
        margin-top: 50px;
    }
</style>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Halaman: Daftar</title>
</head>
<body>
    <div>
        <?php
        if(isset($_POST['username'])) {
            $nama = $_POST['nama'];
            $username = $_POST['username'];
            $password = md5($_POST['password']);

            $query = mysqli_query($koneksi, "INSERT INTO users(nama, username, password) value('$nama', '$username', '$password')");
            if($query) {
                echo '<script>alert("Selamat, anda berhasil mandaftarkan acc anda!")</script>';
            } else {
                echo '<script>alert("Maaf, pendaftaraan acc mu gagal")</script>';
            }
        }

    ?>

    <form action="" method="post">
        <table align="center">
            <tr>
                <td colspan="2" align="center">
                    <h3>Pendaftaran User</h3>
                </td>
            </tr>
            <tr>
                <td>Nama</td>
                <td><input type="text" name="nama"></td>
            </tr>
            <tr>
                <td>Username</td>
                <td><input type="text" name="username"></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="password" name="password"></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <button type="submit">Daftarkan acc</button>
                    <a href="login.php">Login</a>
                </td>
            </tr>
        </table>
    </form>
    </div>
</body>
</html>