<?php

include 'config.php'; // DB connection

// Required: id
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;

if ($id <= 0) {
    echo "Invalid ID";
    exit;
}

// Fields to update
$amount  = $_POST['amount'] ?? null;
$trnxid  = $_POST['trnxid'] ?? null;
$sender  = $_POST['sender'] ?? null;
$gateway = $_POST['gateway'] ?? null;
$method  = $_POST['method'] ?? null;
$status  = $_POST['status'] ?? null;

$setValues = [];

if ($amount !== null)  $setValues[] = "amount='$amount'";
if ($trnxid !== null)  $setValues[] = "trnxid='$trnxid'";
if ($sender !== null)  $setValues[] = "sender='$sender'";
if ($gateway !== null) $setValues[] = "`Gateway`='$gateway'";
if ($method !== null)  $setValues[] = "`Method`='$method'";
if ($status !== null)  $setValues[] = "status='$status'";

if (empty($setValues)) {
    echo "No Data";
    exit;
}

$setQuery = implode(", ", $setValues);

$sql = "UPDATE ShuvoPays SET $setQuery WHERE id = $id";

if ($conn->query($sql)) {
    echo "Update Done";
} else {
    echo "Update Failed";
}

?>