<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo "Access Denied";
    exit();
}

include 'config.php';

foreach(array('Tittle', 'Image', 'Length', 'id') as $field) {
    if(!isset($_POST[$field]) || trim($_POST[$field]) == '') {
        echo $field." is required";
        exit();
    }
}

$sql = "UPDATE category SET Tittle = ?, Image = ?, Length = ? WHERE id = ?";

$stmt = $conn->prepare($sql);
if ($stmt) {
    $stmt->bind_param("ssss", $_POST['Tittle'], $_POST['Image'], $_POST['Length'], $_POST['id']);

    if ($stmt->execute()) {
        echo "Update Successful";
    } else {
        echo "Update Failed";
    }
    $stmt->close();
} else {
    echo "Update Failed";
}
$conn->close();
?>