<?php
header("Access-Control-Allow-Origin: *");
include 'conexion.php';
$table = 'products';


$getJson = file_get_contents('php://input');
$json = json_decode($getJson);
$id = $json->id;
$sql = $connect->query("SELECT * FROM " . $table . " WHERE product_id='" . $id . "'");


while ($fetchSql = $sql->fetch_assoc()) {
    $hasil = $fetchSql;
}

if ($sql->num_rows == 1) {

    $response = array(
        'error' => false,
        'message' => null,
        'data' => $hasil
    );
} else {
    $response = array(
        'error' => true,
        'message' => 'Product Unavailable',
        'data' => null
    );
}

header('Content-Type: application/json');
echo json_encode($response);
