Search code examples
phpundefined-index

How to solve undefined index error


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


Solution

  • 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
    }