Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined index: page in

Ok I have the above error on my page, I am using PHP 5.3 for the first time, and have used this code before but never had this notice, so I was hoping for some guidance. I have looked at some questions but when I try to apply the solution to my bit of code it doesn't seem to work.

This code is a PHP pagination script from paper mashup and so if I can find the answer it may help anybody else who is also using this code and experiences the same problem.

the piece of code which is generating the notice is this -

$page = mysql_escape_string($_GET['page']);
if($page){
    $start = ($page - 1) * $limit; 
}else{
    $start = 0; 
    }   

From what I have read it was suggested to add isset and so changed the code to look like it does below, however i still get the same error.

$page = mysql_real_escape_string($_GET['page']);
 if(!isset($page)){
    $start = ($page - 1) * $limit; 
}else{
    $start = 0; 
    }   

Any advice would be appreciated.

Thanks

Stan

like image 411
user1678816 Avatar asked Sep 17 '12 23:09

user1678816


1 Answers

The 'undefined index' error is basically telling you that you tried to get something from an array using an index for which there is no matching element.

In this case, the problem is in the line above your isset() call. The index 'page' is not defined in your $_GET array. So you need to first check if $_GET['page'] is set:

if (isset($_GET['page'])) {
  $page = mysql_real_escape_string($_GET['page']);
  // do more stuff
}
like image 85
Peter Gluck Avatar answered Sep 22 '22 03:09

Peter Gluck