Im new to PHP and I have been following a tutorial on youtube. I copied the same code showed on youtube and on the video their seemed to be no errors, and when I tried checking the code on virtual studio the PHP debugger showed no mistakes. But when I try checking it on the localhost, this notification shows up. "Notice: Undefined index: heartrate in C:\xampp\htdocs\testcode\trial2.php on line 23". Pls tell me what I’m doing wrong.
This is the code
<?php
$dbuser = 'root';
$dbpass = '78952';
$dbhost = 'localhost';
class thesis_final{
public $link='';
function __construct($heartrate){
$this->connect();
$this->storeInDB($heartrate);
}
function connect(){
$this->link = mysqli_connect('$dbhost','$dbuser','$dbpass') or die('Cannot connect to the DB');
mysqli_select_db($this->link,'<example>') or die('Cannot select the DB');
}
function storeInDB($heartrate){
$query = "insert into <thesis_final> set heartrate='".$heartrate."'";
$result = mysqli_query($this->link,$query) or die('Errant query: '.$query);
}
}
if($_GET['heartrate'] != ''){
$thesis_final=new thesis_final($_GET['heartrate']);
}
?>
>Solution :
Instead of checking if $_GET[‘heartrate’] is ”, use isset.
Example:
if (isset($_GET['heartrate'])) {
$thesis_final = new thesis_final($_GET['heartrate']);
}