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

$old_number = $_POST['old_number'];
$name       = $_POST['name'];
$number     = $_POST['number'];

$sql = "UPDATE Contact SET name = ?, from_number = ? WHERE from_number = ?";
$stmt = $con->prepare($sql);

if ($stmt) {
    $stmt->bind_param("sss", $name, $number, $old_number);

    if ($stmt->execute()) {
        echo "Contact updated successfully!";
    } else {
        echo "Error updating record: " . $stmt->error;
    }

    $stmt->close();
} else {
    echo "Error preparing statement: " . $con->error;
}

$con->close();
?>
