<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
include 'config.php';

$query = "SELECT category_id, category_name FROM categories";
$result = $conn->query($query);

if (!$result) {
    error_log("Query failed: " . $conn->error);
    die(json_encode(["error" => "Query failed: " . $conn->error]));
}

$categories = [];
while ($row = $result->fetch_assoc()) {
    $categories[] = $row;
}

$conn->close();

echo json_encode($categories);
?>
