//header('Content-Type: text/html; charset=utf-8');
date_default_timezone_set('Asia/Bangkok');
$date = date('Y-m-d H:i:s');
ini_set('max_execution_time', 300);
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$barcode = $_POST['barcode'];
$store = $_POST['store'];
}
else
{
$barcode = $_GET['barcode'];
$store = $_GET['store'];
}
/* if(strlen(trim($barcode))!=13)
exit; */
include("connect.php");
mysqli_query($mysqli,"SET character_set_results=utf8");
mysqli_query($mysqli,"SET character_set_client=utf8");
mysqli_query($mysqli,"SET character_set_connection=utf8");
if(strlen($store)>0)
{
$result = $mysqli->query("SELECT * FROM allstores WHERE barcode = '$barcode' AND store = '$store'");
$num_rows = mysqli_num_rows($result);
if($num_rows==0)
$result = $mysqli->query("SELECT * FROM allstores WHERE barcode = '$barcode' ORDER BY ctime DESC");
}
else
$result = $mysqli->query("SELECT * FROM allstores WHERE barcode = '$barcode' ORDER BY ctime DESC");
$num_rows = mysqli_num_rows($result);
if($num_rows>0)
{
$row=mysqli_fetch_row($result);
$productname = $row[1];
$price = $row[2];
$amount = $row[4];
$store = $row[6];
if($price>0)
{
echo $productname." ราคา:".strval($price)." บาท";
$amount = $amount+1;
/* $sql = "UPDATE allstores SET amount='$amount',ctime = '$date' WHERE barcode = '$barcode' AND store = '$store'";
if (!mysqli_query($mysqli, $sql))
echo "" . mysqli_error($mysqli); */
exit;
}
}
else
{
/* $sql = $mysqli->query("SELECT * FROM notfound WHERE barcode = '$barcode'");
$num_rows = mysqli_num_rows($sql);
if($num_rows==0)
{
$sql = "INSERT IGNORE INTO notfound (barcode,ctime) VALUES ('$barcode','$date')";
if (!mysqli_query($mysqli, $sql))
echo "".mysqli_error($mysqli);
} */
}
?>