Arduino to php database php guidance

Hi guys i am testing the code ive got from youtube which is to send the data from arduino to php database. I find it working and it sends data to database but i am confused as on why the php code named data.php said that: when i try to open it in localhost. Please help me and give me guidance thanks.

Warning : Undefined array key "temperature" in C:\xampp\htdocs\ethernet\data.php on line 20

Here is the php code:

<?php
class dht11{
 public $link='';
 function __construct($temperature, $humidity){
  $this->connect();
  $this->storeInDB($temperature, $humidity);
 }
 
 function connect(){
  $this->link = mysqli_connect('localhost','root','') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'temphumidnew') or die('Cannot select the DB');
 }
 
 function storeInDB($temperature, $humidity){
  $query = "insert into dht11 set humidity='".$humidity."', temperature='".$temperature."'";
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
 
}
if($_GET['temperature'] != '' and  $_GET['humidity'] != ''){
 $dht11=new dht11($_GET['temperature'],$_GET['humidity']);
}


?>

If you open the file in local host it wont have any querystring parameters unless you put them in the url.

The code is checking that the variables are not blank, but the variables dont even exist. Open in localhost as data.php?temperature=12&humidity=80 and it should work fine

1 Like

Thanks for that answer sir it helps me

Can you post the link to the video?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.