当前位置:首页 > PHP教程 > PHP高级教程

php Undefined index和Undefined variable的解决方法

$act=$_post['act'];

用以上代码总是提示
notice: undefined index: act in f:windsflybookpost.php on line 18

另外,有时还会出现

 引用内容
notice: undefined variable: submit ......

等一些这样的提示

原因:由于变量未定义引起的

解决方法:
1) error_reporting设置:
找到error_reporting = e_all
修改为error_reporting = e_all & ~e_notice

2) register_globals设置:
找到register_globals = off
修改为register_globals = on

notice: undefined variable: email in d:php5enoteaddnote.php on line 9
  notice: undefined variable: subject in d:php5enoteaddnote.php on line 9
  notice: undefined variable: comment in d:php5enoteaddnote.php on line 9
  ........
  本来php是不需要定义变量的,但是出现这种情况应该怎么办呢?
  只要在c:windows找出php.ini的
  在php.ini中的302行 error_reporting = e_all
  修改成
  error_reporting = e_all & ~e_notice再重启apache2.2就行了
  解决方法:修改php.ini
  将: error_reporting = e_all
  修改为:error_reporting = e_all & ~e_notice
  如果什么错误都不想让显示,直接修改:
  display_errors = off
  如果你没有php.ini的修改权限,可在php头部加入
  ini_set("error_reporting","e_all & ~e_notice");
  即可

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!