-5

error: "Notice: Undefined index: page in C:\wamp\www\digi\admin\config\setup.php on line 8"

my code is:

    <?php
   #setup document
                      //host-username-password-database_name
   $db = mysqli_connect('localhost','root','','dynamic');

   if($_GET['page'] == "")
               {$pg = 'home';}
   else
               {$pg = $_GET['page'];}

   include('/functions/sandbox.php');

   include('/functions/template.php');

   $page_title =  get_page_title($db,$pg);
?>
Jorge Y. C. Rodriguez
  • 3,394
  • 5
  • 38
  • 61
  • 2
    This question appears to be off-topic because it is about basic debugging – John Conde Sep 30 '13 at 20:37
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Sammitch Sep 30 '13 at 20:38
  • 1
    It means there's no `$_GET` value called "page" – David Sep 30 '13 at 20:38
  • RTFM: http://php.net/manual/en/language.types.array.php Example #7 – Marc B Sep 30 '13 at 20:39
  • Take a look in the Related sidebar `---->`, plenty of similar questions there `:)`. – halfer Sep 30 '13 at 20:40
  • @john conde i don't know about "basic debugging" – user2832607 Sep 30 '13 at 21:02
  • @sammitch this is not duplicate – user2832607 Sep 30 '13 at 21:03
  • @david there is a $_GET value called 'page' – user2832607 Sep 30 '13 at 21:04
  • @halfer thank you. i fixed it using if(empty($_GET['page'])) – user2832607 Sep 30 '13 at 21:05
  • @user2832607: You say there is, but the PHP interpreter says there isn't. I'm more inclined to believe the PHP interpreter. – David Sep 30 '13 at 21:17
  • Yes, it is a duplicate. There are currently over ***THREE THOUSAND QUESTIONS*** on StackOverflow regarding 'Undefined Index' messages. This *exact* same question is asked a dozen times per day, and the answer is always the same. Try using the search box or google next time. – Sammitch Oct 01 '13 at 00:12
  • It means the variable is not declared
    Declare your variables, for example when you try to append a string to an undefined variable. Or use `isset() / !empty()` to check if they are declared before referencing them.
    – Regolith Aug 18 '16 at 10:03

1 Answers1

4

$_GET['page'] is not defined. To correctly check if it exists you should use isset():

 if(isset($_GET['page'])) {$pg = 'home';} else {$pg = $_GET['page'];}
John Conde
  • 217,595
  • 99
  • 455
  • 496