Undefined error in code

I have a problem with my php code, I am getting undefined index on both lines:

$Page = $_GET["Page"];    
if(!$_GET["Page"])

      

It only happens on the first page .. of course it should only happen then .. can anyone tell me how to solve it?

I found something like this, but I cannot completely remove the notification.

(!empty($_GET['query_age']) ? $_GET['query_age'] : null);

      

I need to know how to implement it in my code, but I cannot ..

thank

+3


source to share


5 answers


$page = isset($_GET['Page']) ? $_GET['Page']: '';

      



Then you can work with $page

. An indexed index is because the index is not set to $_GET

, because you don't have a GET parameter. Then you have to set this value in your code.

+1


source


$Page = null;
if (array_key_exists('Page', $_GET)) {
    $Page = $_GET['Page'];
}

      



is the most explicit and accurate thing you can do. You can also use isset()

.

+1


source


$Page = isset($_GET["Page"])?$_GET["Page"]:""; 

      

+1


source


if(isset($_GET["Page"])) {
     $Page = $_GET["Page"];
} else {
     $Page = "";
}

      

0


source


Yours is $_GET['Page']

empty and you will receive a notification Undefined

(not an error message). So, before assigning this $Page

, you should check if there is any data:

if(isset($_GET['Page'])) {
    $Page = $_GET['Page'];
} else {
    $Page = ''; // $_GET['Page'] is undefined
}

      

0


source







All Articles