<?php
// edit.php

include 'includes/config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = $_POST['id'];
    $actualName = $_POST['actual_name'];
    $shortName = $_POST['short_name'];
    $allowDecimal = $_POST['allow_decimal'];

    $sql = "UPDATE `units` SET `actual_name` = :actual_name, `short_name` = :short_name, `allow_decimal` = :allow_decimal WHERE `id` = :id";
    $stmt = $conn->prepare($sql);

    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->bindParam(':actual_name', $actualName, PDO::PARAM_STR);
    $stmt->bindParam(':short_name', $shortName, PDO::PARAM_STR);
    $stmt->bindParam(':allow_decimal', $allowDecimal, PDO::PARAM_INT);

    try {
        $stmt->execute();
        echo "Update successful";
    } catch (PDOException $e) {
        echo "Update failed: " . $e->getMessage();
    }
}
?>
