Page 1 of 1

Undefined index

Posted: Mon Oct 19, 2009 4:57 pm
by spacebiscuit
Hi guys,

Can anyone help with this error which is driving me crazy. My pache server is reporting the following warning:

PHP Notice: Undefined index: pageno in c:\\program files\Apache2\\htdocs\\index_video.php on line 27

The code in question is:

Code: Select all

$limits=get_limits('video',$_GET['pageno']);
My script works as expected but I can't stop the warning from showing up in my srver logs.

Any help would very much be appreciated.

Thanks in advance,

Rob.

Re: Undefined index

Posted: Mon Oct 19, 2009 5:00 pm
by John Cartwright
$_GET['pageno'] will only exist when you have ?pageno= in the url. More than likely, your initial page does not contain this value. It is better practice to check the existance of user input, and/or give a default value.


i.e.,

Code: Select all

 
$pageno = 1;
if (isset($_GET['pageno'])) {
   $pageno = (int)$_GET['pageno'];
} 
 
// or
 
$pageno = isset($_GET['pageno']) ? (int)$_GET['pageno'] : 1;

Re: Undefined index

Posted: Mon Oct 19, 2009 5:12 pm
by spacebiscuit
Thanks for the prompt reply and I now understand why Apache is outputting the warning.

You're correct in that when my script is initially called the 'pagno' variable is not set. I'm not passing variables via URL as I'm using sessions variables instead. Therefore I simply have to ensure that the 'pageno' variable is initialised as follows:

Code: Select all

if(!isset($_GET['pageno'])){
     $_GET['pageno']=1;
                           }
Then the warning ceases!

Many thanks,

Rob.