Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am getting this undefined index error line 23

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']);
}
?>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of checking if $_GET[‘heartrate’] is ”, use isset.

Example:

if (isset($_GET['heartrate'])) {
    $thesis_final = new thesis_final($_GET['heartrate']);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading