<?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 = [
        "Tdstatu" => "status",     
        "Inputquantity" => "quantity",
        "Inputweight" => "weight",
        "Inputsize" => "size",
        "InputcurrentPrice" => "current_price",
        "Inputprice" => "price",
        "Inputseller" => "seller",
        "Inputgks" => "gks",
        "Inputproduct_name" => "product_name",
        "Inputdiscount_code" => "discount_code",
        "Inputperson" => "person",
        "Inputdiscount_special" => "discount_special",
        "Inputdiscount" => "discount"
    ];

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