<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo "Access Denied";
    exit();
}

include 'config.php';

foreach(array('Progress', 'id', 'Auth') as $field) {
    if(!isset($_POST[$field]) || trim($_POST[$field]) == '') {
        echo $field." is required";
        exit();
    }
}

$sql = "UPDATE trx SET Progress = ? WHERE id = ?";
$stmt = $conn->prepare($sql);

if ($stmt) {
    $stmt->bind_param("ss", $_POST['Progress'], $_POST['id']);

    if ($stmt->execute()) {

        $update = $conn->prepare("UPDATE users SET Request='On' WHERE Auth=?");
        $update->bind_param("s", $_POST['Auth']);

        if ($update->execute()) {
            echo "Reject Successful";
        } else {
            echo "Reject Failed";
        }

        $update->close();

    } else {
        echo "Reject Failed";
    }

    $stmt->close();

} else {
    echo "Reject Failed";
}

$conn->close();
?>