How to solve undefined index error

Alin picture Alin · Sep 19, 2013 · Viewed 33.7k times · Source
if(isset($_SESSION['evt_year']) 
   || isset($_SESSION['evt_title']) 
   || isset($_SESSION['evt_sdate']) 
   || isset($_SESSION['evt_place']) 
   || isset($_SESSION['evt_stime']) 
   || isset($_SESSION['evt_etime']) 
   || isset($_SESSION['evt_desc'])) {
    $output.=$_GET['title']; //the error is here
}
else {
    $output.="";
}

Notice the error I got:

Undefined index: title in C:\xampp\htdocs\ICT\abc\cal1\EventCalender\classes\EventRecordForm.php on line 13

Answer

AD7six picture AD7six · Sep 19, 2013

You are testing a lot of variables, but none of them are the variable that is read from.

should be e.g.:

if (isset($_GET['title'])) {
     $output.=$_GET['title']; // there is no error here
}