<?php
session_start();
if (!isset($_SESSION['user_id'])) exit;

$host = 'localhost';
$user = 'majapahi_omnich';
$pass = 'A1b2c3d4.,@';
$db   = 'majapahi_omnich';
$conn = new mysqli($host, $user, $pass, $db);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $phone = $conn->real_escape_string($_POST['phone']);
    $label = $conn->real_escape_string($_POST['label']);

    if (!empty($phone)) {
        $sql = "UPDATE contacts SET label = '$label' WHERE phone_number = '$phone'";
        if ($conn->query($sql)) {
            echo "success";
        } else {
            echo "error";
        }
    }
}
?>