Heim  >  Artikel  >  Backend-Entwicklung  >  PHP错误Notice: Undefined index解决方法_PHP教程

PHP错误Notice: Undefined index解决方法_PHP教程

WBOY
WBOYOriginal
2016-07-21 14:54:001440Durchsuche

  我把error_reporting设成 E_ALL了.

  在读数据时 如$row['name']时

  会出现很多Notice: Undefined index: 错误,

  应该怎么办? error_reporting(E_ALL & ~ E_NOTICE ) 这样吗?

  Undefined index:是指你代码里存在:“变量还未定义、赋值就使用”错误,这个不是致命错误,不会让你php代码运行强行中止,但是有潜在出问题危险,因此建议修改~~~~

  notice内容都是这类不很影响使用非致命问题

  用E_ALL & ~ E_NOTICE可以关闭notice显示,不过,建议还是改代码更好一点:)

  代码总是写规范一点好,将来可以少出问题啊:)

  开开这个notice显示,对于调错误也很有帮助~~~~

  如果你$row是通过 $row = mysql_fetch_array($result)来的,

  而echo $row['name']的时候又出现了Notice: Undefined index: 的问题,那么就有可能是:

  1, SQL语句有错,没有读出name这个字段里的值,

  2. SQL语句执行失败,什么值都没读出来

  3. SQL即没错也没失败,但是没有查询到符合条件的纪录,自然也就没有$row['name']

  4. 其他

  notice一般提示关于与执行代码没有直接关系的错误,但不要忘记,notice有时会返回一些多余的错误信息

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/364675.htmlTechArticle我把error_reporting设成 E_ALL了. 在读数据时 如$row['name']时 会出现很多Notice: Undefined index: 错误, 应该怎么办? error_reporting(E_ALL ~ E_NOTICE ) 这样吗...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn