<?php 
require '../assets/config-data.php';
$pasar = mysqli_real_escape_string($data, $_REQUEST['preresult']);
$angka = mysqli_real_escape_string($data, $_REQUEST['angkaresult']);
$j = mysqli_real_escape_string($data, $_REQUEST['jamresult']);
$jam = $j . date(" H:i:s");



$spre = "SELECT * FROM result_lotto WHERE res_pasaran = '$pasar' AND DATE(res_jam) = '$j'";
$qpre = mysqli_query($data, $spre);

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

$updatestatus = "INSERT INTO result_lotto(res_pasaran, res_angka, res_jam) VALUES('$pasar', '$angka', '$jam')";
$bindstats = mysqli_query($data, $updatestatus);


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

} else {

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

}

}

?>