Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $json = file_get_contents('php://input');
- $data = json_decode($json);
- $room = $data->room;
- $polybag = $data->polybag;
- $lux_m = $data->lux_m;
- $moistur = $data->moistur;
- $suhu_m = $data->suhu_m;
- $suhu_g = $data->suhu_g;
- $hum_g = $data->hum_g;
- $lux_g = $data->lux_g;
- $lat = $data->lat;
- $lon = $data->lon;
- $_ts = $data->ts;
- $time = strtotime($_ts);
- $ts = date("Y-m-d H:i:s", $time);
- $servername = "localhost";
- $username = "user";
- $password = "";
- $dbName = "tbl_kebun";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbName);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }else{
- // echo "sukses to server";
- }
- if($room == 100){
- $sql = "INSERT INTO room1 (polybag, lux_m, moistur, suhu_m, suhu_g, hum_g, lux_g, lat, lon, time_g)
- VALUES ('$polybag', '$lux_m', '$moistur', '$suhu_m','$suhu_g', '$hum_g', '$lux_g', '$lat', '$lon', '$ts')";
- if (mysqli_query($conn, $sql)) {
- $sts_crud = '{"status":1}';
- echo $sts_crud;
- } else {
- $sts_crud = '{"status":0}';
- echo $sts_crud;
- }
- mysqli_close($conn);
- }
- if($room == 101){
- //echo "get room 101";
- $sql = "INSERT INTO room2 (polybag, lux_m, moistur, suhu_m, suhu_g, hum_g, lux_g, lat, lon, time_g)
- VALUES ('$polybag', '$lux_m', '$moistur', '$suhu_m','$suhu_g', '$hum_g', '$lux_g', '$lat', '$lon', '$ts')";
- if (mysqli_query($conn, $sql)) {
- $sts_crud = '{"status":1}';
- echo $sts_crud;
- } else {
- $sts_crud = '{"status":0}';
- echo $sts_crud;
- }
- mysqli_close($conn);
- }
- if($room == 102){
- //echo "get room 102";
- //echo "get room 101";
- $sql = "INSERT INTO room3 (polybag, lux_m, moistur, suhu_m, suhu_g, hum_g, lux_g, lat, lon, time_g)
- VALUES ('$polybag', '$lux_m', '$moistur', '$suhu_m','$suhu_g', '$hum_g', '$lux_g', '$lat', '$lon', '$ts')";
- if (mysqli_query($conn, $sql)) {
- $sts_crud = '{"status":1}';
- echo $sts_crud;
- } else {
- $sts_crud = '{"status":0}';
- echo $sts_crud;
- }
- mysqli_close($conn);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement