<?php
require_once('dbconnection.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = intval($_POST['id']);
    $column = $_POST['column'];
    $value = mysqli_real_escape_string($con, $_POST['value']);

    $allowed_columns = ['name', 'from_number', 'to_number'];
    if (!in_array($column, $allowed_columns)) {
        echo 'Invalid column.';
        exit;
    }

    $query = "UPDATE Contact SET $column = '$value' WHERE id = $id";
    if (mysqli_query($con, $query)) {
        echo 'Success';
    } else {
        echo 'Error: ' . mysqli_error($con);
    }
}
?>
