<?php include("auth.php"); ?>

<!DOCTYPE html>
<html>
<head>
    <title>Add Category</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">

<div class="container mt-5">
    <div class="card shadow">
        <div class="card-header bg-dark text-light">
            Add Category
        </div>

        <div class="card-body">
            <form method="post">
                <div class="mb-3">
                    <label>Category Name</label>
                    <input type="text" name="name" class="form-control" required>
                </div>

                <button name="save" class="btn btn-success">Save</button>
                <a href="categories.php" class="btn btn-secondary">Back</a>
            </form>
        </div>
    </div>
</div>

<?php
if (isset($_POST['save'])) {
    $stmt = $conn->prepare("INSERT INTO categories (name) VALUES (?)");
    $stmt->bind_param("s", $_POST['name']);
    $stmt->execute();
    header("Location: categories.php");
}
?>
</body>
</html>
