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

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['token']) && isset($_POST['market'])) {

    $token = mysqli_real_escape_string($data, $_POST['token']);
    $market = strtolower(mysqli_real_escape_string($data, $_POST['market']));

    $delete_pasaran = "DELETE FROM pasaran_web WHERE id = '$token'";
    $query_pasaran = mysqli_query($data, $delete_pasaran);

    $delete_results = "DELETE FROM result_lotto WHERE res_pasaran = '$market'";
    $query_results = mysqli_query($data, $delete_results);

    $delete_prediksi = "DELETE FROM prediksi_togel WHERE pasaran_prediksi = '$market'";
    $query_prediksi = mysqli_query($data, $delete_prediksi);

    if ($delete_pasaran && $delete_results && $delete_prediksi) {
        echo 'Pasaran Berhasil di Hapus';
    } else {
        return http_response_code(500);
    }
} else {
    return http_response_code(500);
}
