<?php
require_once("db_connect.php");
$key="tPmAT5Ab3j7F9";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  	if($key==test_input($_POST["key"])){

        $type=test_input($_POST["type"]);

        if($type="on_off"){
            $sql="SELECT on_off FROM system WHERE id=1";
            $result=$conn->query($sql);
                $result=$result->fetch_assoc();
                if ($result["on_off"]==1){
                    echo"on";

                }else{
                     echo"off";
                }
        }else{ 
            echo"error";         
        }
    }else{
        echo "wrong key";
    }
}
else {
    echo "No data POSTed with HTTP POST.";
}

function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

?>