<?php
// Database connection
require_once 'shikanisha.kts.php';

// Query to fetch product details
$sql = "SELECT product_id, product_name, shop_quantity, selling_price FROM products";

$result = mysqli_query($conn, $sql);

if (!$result) {
    die("Error in SQL query: " . mysqli_error($conn));
}

// Create an array to store product details
$products = [];

// Fetch product details and add them to the array
while ($row = mysqli_fetch_assoc($result)) {
    $products[] = $row;
}

// Close the database connection
mysqli_close($conn);

// Set the response content type to JSON
header('Content-Type: application/json');

// Return the product details as JSON
echo json_encode($products);
?>
