<?php 
require '../assets/config-data.php';

$user = mysqli_real_escape_string($data, $_REQUEST['username']);
$pass = mysqli_real_escape_string($data, $_REQUEST['passadmin']);

$new_pass = password_hash($pass, PASSWORD_DEFAULT);

$spre = "SELECT * FROM lomba_credential WHERE nama_pengguna = '$user'";
$qpre = mysqli_query($data, $spre);

if(mysqli_num_rows($qpre) > 0) {
    echo '<script>
                alert("Username '.$user.' sudah ditambahkan sebelumnya. Gagal tambah Admin.");
                window.location.href = "../dashboard.php?hal=tambahadmin";
    </script>';
} else {

$updatestatus = "INSERT INTO lomba_credential(nama_pengguna, password, tgl_daftar) VALUES('$user', '$new_pass', '$today')";
$bindstats = mysqli_query($data, $updatestatus);


if($bindstats) {
    echo '
    <script>
        alert("Admin add Successfully!!");
        window.location.href = "../dashboard.php?hal=tambahadmin";
    </script>
    ';

} else {

    echo '
    <script>
        alert("ERROR on Adding!!");
        window.location.href = "../dashboard.php?hal=tambahadmin";
    </script>
    ';

}

}

?>