duanpuluan0480
2014-06-29 17:12 阅读 389
已采纳

如何解决“注意:未定义的索引:......”

how can i hide the php notice by solving the issue.

my code

if(empty($_GET['mode']) && !$_GET['page']) { 
    include($basepath.'/templates/template.home.php');
}

Notice: Undefined index: page in /var/www/public_html/index.php on line 1

i tried like this

if(empty($_GET['mode']) && !isset($_GET['page']) && !$_GET['page']) { 
    include($basepath.'/templates/template.home.php');
}

but still showing the

Notice: Undefined index: page in /var/www/public_html/index.php on line 1

how can i solve/fix it ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dongre6227 dongre6227 2014-06-29 17:21

    The problem is that you use in both statements !$_GET['page'] when using && operator.

    When you use !$_GET['page'] in both cases even if you added !isset($_GET['page'] this condition is checked in $_GET['mode'] is empty.

    You simple should probably change your statement from:

    if(empty($_GET['mode']) && !$_GET['page']) { 
        include($basepath.'/templates/template.home.php');
    }
    

    into

    if(empty($_GET['mode']) && !isset($_GET['page'])) { 
        include($basepath.'/templates/template.home.php');
    }
    

    In this case simple if $_GET['page'] is not set (and of course mode is empty) you should include homepage template

    点赞 评论 复制链接分享
  • douzhang6646 douzhang6646 2014-06-29 17:14

    Either mode or page isn't present in the array $_GET - so you need to test for it using array_key_exists

    点赞 评论 复制链接分享

相关推荐