<?php

$servername = "163.44.198.63:3306";
$dbname = "cp329720_siamatic";
$username = "cp329720";
$password = "Siam1219!";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

		$dev_id=  $_GET['dev_id'];
		$dev_sn= $_GET['dev_sn'];
		$temp_value= $_GET['temp_value'];

		$temp_avg= $_GET['temp_avg'];
		$humidity_value= $_GET['humidity_value'];
		$humidity_avg= $_GET['humidity_avg'];
		$send_time= $_GET['send_time'];

		$ac= $_GET['ac'];
		$door= $_GET['door'];
		$internet= $_GET['internet'];
		$probe= $_GET['probe'];
		$bettery= $_GET['bettery'];
       		$ambient= $_GET['ambient'];

$sql_1 = "INSERT INTO logs_reals (dev_id, dev_sn, temp_value, temp_avg, humidity_value, humidity_avg, send_time, 
			ac, door, internet, probe, bettery,ambient) 
			VALUES ('$dev_id','$dev_sn','$temp_value','$temp_avg','$humidity_value','$humidity_avg','$send_time',
			$ac,$door,$internet,$probe,$bettery,$ambient)";



/*
$sql_1 = "INSERT INTO logs_reals (dev_id, dev_sn, temp_value, temp_avg, humidity_value, humidity_avg,  
			ac, door, internet, probe, bettery,ambient) 
			VALUES ('$dev_id','$dev_sn','$temp_value','$temp_avg','$humidity_value','$humidity_avg',
			$ac,$door,$internet,$probe,$bettery,$ambient)";
*/

if ($conn->query($sql_1) === TRUE) {
	
			$sql_1 = "INSERT INTO logs_days (dev_id, dev_sn, temp_value, temp_avg, humidity_value, humidity_avg, send_time, 
				ac, door, internet, probe, bettery,ambient) 
				VALUES ('$dev_id','$dev_sn','$temp_value','$temp_avg','$humidity_value','$humidity_avg','$send_time',
				$ac,$door,$internet,$probe,$bettery,$ambient)";

				if ($conn->query($sql_1) === TRUE) { 
					echo "New record created successfully";
				  }

} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>