<?php
include("configa.php");

if(isset($_POST['id'], $_POST['field'], $_POST['value'])) {
    $id = intval($_POST['id']);
    $field = $_POST['field'];
    $value = mysqli_real_escape_string($conn, $_POST['value']);

    // Map select/textarea names to DB columns
    $map = [
        "TdconfirmNon" => "confirm",
        "TdorderReady" => "orderReady",
        "TdcurrierDeliverd" => "currierDeliverd",
        "Tddelivery" => "delivery",
        "TdcurrierName" => "currierName",
        "Tdreceive" => "receive",
        "Tdpaid" => "paid"
    ];

    if(array_key_exists($field, $map)) {
        $column = $map[$field];
        $sql = "UPDATE final_order_summary SET $column='$value' WHERE id=$id";
        if(mysqli_query($conn, $sql)) {
            echo "Updated successfully";
        } else {
            echo "Error: " . mysqli_error($conn);
        }
    }
}
?>
