File "get-stock.php"
Full path: /home/atrmarke/public_html/atrdemolive.site/bcopy/pages/get-stock.php
File
size: 0.68 KB (700 B bytes)
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
// --- get-stock.php ---
// Returns pr1–pr10 stock values for a given product_type from product_sub table
include('../db/cn.php'); // Ensure this sets up $connection (MySQLi)
$product_type = isset($_GET['product_name']) ? mysqli_real_escape_string($connection, $_GET['product_name']) : '';
if (!$product_type) {
http_response_code(400);
echo json_encode(['error' => 'Product name required']);
exit;
}
$sql = "SELECT * FROM products_sub WHERE product_type = '$product_type'";
$result = mysqli_query($connection, $sql);
if ($result && mysqli_num_rows($result) > 0) {
$stock = mysqli_fetch_assoc($result);
echo json_encode($stock);
} else {
echo json_encode([]);
}
?>