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

// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Retrieve and sanitize form inputs
    $id = (int)$_POST['id'];
    $name = trim($_POST['name']);
    $description = trim($_POST['description']);

    // Check required fields
    if (empty($name) || empty($description)) {
        die("Please fill all required fields.");
    }

    // Prepare the SQL query to update data
    $sql = "UPDATE `brands` SET `name` = :name, `description` = :description WHERE `id` = :id";
    $stmt = $conn->prepare($sql);

    // Bind parameters
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->bindParam(':name', $name, PDO::PARAM_STR);
    $stmt->bindParam(':description', $description, PDO::PARAM_STR);

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