<?php
session_start();
include "config.php";

if (!isset($_SESSION['user'])) {
    echo "unauthorized";
    exit;
}

$cctv_id = (int) ($_POST['cctv_id'] ?? 0);
$cctv_details = $_POST['cctv_details'] ?? '';

if ($cctv_id === 0 || empty($cctv_details)) {
    echo "invalid";
    exit;
}

$cctv_details = mysqli_real_escape_string($con, $cctv_details);

$sql = "UPDATE cctv 
        SET cctv_details = '$cctv_details'
        WHERE id = $cctv_id";

if (mysqli_query($con, $sql)) {
    echo "success";
} else {
    echo "error";
}