//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'];
$amount = $_POST['amount'];
}
else
{
$barcode = $_GET['barcode'];
$amount = $_GET['amount'];
}
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");
$result = $mysqli->query("SELECT * FROM products WHERE barcode = '$barcode'");
$num_rows = mysqli_num_rows($result);
if($num_rows>0)
{
$row=mysqli_fetch_row($result);
/* $productname = $row[1];
$price = $row[2];
$amount = $row[4]; */
$productname = "เซิร์ฟเวอร์หยุดทำงาน!";
$price = 0.01;
$amount = 0;
if($price>0)
{
echo $productname." ราคา:".strval($price)." บาท";
$amount = $amount+1;
$sql = "UPDATE products SET amount='$amount',ctime = '$date' WHERE barcode = '$barcode'";
if (!mysqli_query($mysqli, $sql))
echo "Error updating record: " . mysqli_error($mysqli);
exit;
}
else
$result = $mysqli->query("DELETE FROM products WHERE barcode = '$barcode'");
}
else
{
$sql = $mysqli->query("SELECT * FROM notfound WHERE barcode = '$barcode'");
$num_rows = mysqli_num_rows($sql);
if($num_rows==0)
{
$sql = "INSERT INTO notfound (barcode,ctime) VALUES ('$barcode','$date')";
if (!mysqli_query($mysqli, $sql))
echo "".mysqli_error($mysqli);
}
}
?>