connect_error) { die("Connection failed: " . $conn->connect_error); } if ($_SERVER["REQUEST_METHOD"] === "POST") { $data = json_decode(file_get_contents("php://input"), true); $title = $data["title"]; $description = $data["description"]; $manufacturer = $data["manufacturer"]; $thc_Content = $data["thc_Content"]; $species = $data["species"]; $price = $data["price"]; $categories = $data["categories"]; $sub_categories = $data["sub_categories"]; $featured_image = $data["featured_image"]; $gallery_image = $data["gallery_image"]; $insertSql = "INSERT INTO products (title, description, manufacturer,thc_Content,species,price,categories,sub_categories,featured_image,gallery_image) VALUES ('$title', '$description', '$manufacturer','$thc_Content','$species','$price','$categories','$sub_categories','$featured_image','$gallery_image')"; if ($conn->query($insertSql) === true) { $response = array("message" => "Product created successfully"); } else { $response = array("message" => "Error creating product: " . $conn->error); } echo json_encode($response); } else { $expectedApiKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTUsInVzZXJuYW1lIjoia21pbmNoZWxsZSIsImVtYWl"; if (!isset($_SERVER["HTTP_API_KEY"])) { http_response_code(401); echo json_encode(array("message" => "Unauthorized - Missing API Key")); exit; } $apiKey = $_SERVER["HTTP_API_KEY"]; // Check if the API key matches the expected API key if ($apiKey !== $expectedApiKey) { http_response_code(401); echo json_encode(array("message" => "Unauthorized - Invalid API Key")); exit; } // Handle GET request to fetch all products $sql = "SELECT * FROM products"; $result = $conn->query($sql); $products = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $products[] = $row; } } echo json_encode($products); } $conn->close(); ?>