<?php
include 'includes/config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = $_POST['id'];
    $name = $_POST['name'];
    $short_code = $_POST['short_code'];
    $parent_id = $_POST['parent_id'] ? $_POST['parent_id'] : null;
    $description = $_POST['description'];

    $sql = "UPDATE categories SET name = :name, short_code = :short_code, parent_id = :parent_id, description = :description WHERE id = :id";
    $stmt = $conn->prepare($sql);
    $stmt->execute(['name' => $name, 'short_code' => $short_code, 'parent_id' => $parent_id, 'description' => $description, 'id' => $id]);

    header('Location: categories.php');
}
?>
