0
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

Morten Kristensen
  • 7,412
  • 4
  • 32
  • 52
Alin
  • 21
  • 1
  • 1
  • 5
  • $_GET['title'] hasn't been set. Is the `` withe the name 'title' defined on your form, or is the variable set in your querystring? –  Sep 19 '13 at 07:21
  • the variable set is in the query string. but still got the same undefined error... should i change into some thing else? like REQUEST or POST. – Alin Sep 19 '13 at 07:29
  • @Alin just FYI, this is a notice. Which you can avoid printing in page by putting this `error_reporting(E_ALL ^ E_NOTICE)` code on top of your php files. This will print out all other errors except notices. That being said; best practices for this kind of error is to define variables. – Maz Sep 19 '13 at 08:05

3 Answers3

4

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
}
AD7six
  • 63,116
  • 12
  • 91
  • 123
1

Just check isset() on the $_GET variable before appending it:

if ( isset( $_GET['title'] ) ) $output.=$_GET['title'];

The error occurs because $_GET['title'] has not been populated.

Patrick Moore
  • 13,251
  • 5
  • 38
  • 63
1

Before you check/use a variable, it needs to be defined or checked it it really exists. This has been introduced in PHP 5.3.0.

WRONG:

$output = $_GET['title'];

CORRECT:

if (isset($_GET['title'])) {
    $output = $_GET['title'];
}
Sliq
  • 15,937
  • 27
  • 110
  • 143