<?php
//setting header to json 
    header('Content-Type: application/json');
    header("Access-Control-Allow-Origin: *");

    $id = $_POST["id"];  // get internal sensor id from js
    $name = $_POST["name"];  // get value
    require '../php/database.php';

    
    // $sql = "UPDATE ds18b20 SET `name`='$name' WHERE `address`='$id'";
    $sql = "UPDATE probes SET `name`='$name' WHERE `address`='$id'";
    
    if ($mysqli->query($sql) === TRUE) {
        // echo "Widget Visible updated successfully";
    } else {
        // echo "Error updating Widget Visible: " . $mysqli->error;
    }
    // //query to get data from the table
    // $result = $mysqli->query("SELECT * FROM ds18b20 WHERE address = '$id'");

    // if (!$result) {  // run query
    //     die($mysqli->error);
    // }
    
    // // echo $result->num_rows;
    // if ($result->num_rows > 0) {  // check if duplicate
    //     // sensor already in database
    // } else {  // insert record as it doesn't exist
    //     $result = $mysqli->query("INSERT IGNORE INTO ds18b20 (address, name, plugged, graphVisible) VALUES ('".$id."', '".$name."', '1', '1')");
    //     if ($result === false) {echo "SQL error:".$mysqli->error;}
    // }

    //close connection
    $mysqli->close();
?>