search
Homephp教程php手册undefined index: php中提示Undefined index的解决方法


我们经常接收表单POST过来的数据时报Undefined index错误,如下:$act=$_POST['action'];
用以上代码总是提示
Notice: Undefined index: act in D:\test\post.php on line 20
另外,有时还会出现
Notice: Undefined variable: Submit ...... 等一些这样的提示
 
出现上面这些是 PHP的提示而非报错,PHP本身不需要事先声明变量即可直接使用,但是对未声明变量会有提示。一般作为正式的网站会把提示关掉的,甚至连错误信息也被关掉。
 
解决方法:
1)在变量前面 加上一个 @ ,如  if(@$_GET['action']=='save') { ...
2) 修改 php.ini 中的 error配置下错误显示方式:将error_reporting = E_ALL 修改为
   error_reporting = E_ALL& ~E_NOTICE
   修改后重启下APCHE服务器,方可生效。
 
 
------------------------------------------------------------------------------
[PHP-Core-Error]
error_reporting = E_ALL & ~E_NOTICE
; 错误报告级别是位字段的叠加,推荐使用 E_ALL E_STRICT
; 1 E_ERROR 致命的运行时错误
; 2 E_WARNING 运行时警告(非致命性错误)
; 4 E_PARSE 编译时解析错误
; 8 E_NOTICE 运行时提醒(经常是bug,也可能是有意的)
; 16 E_CORE_ERROR PHP启动时初始化过程中的致命错误
; 32 E_CORE_WARNING PHP启动时初始化过程中的警告(非致命性错)
; 64 E_COMPILE_ERROR 编译时致命性错
; 128 E_COMPILE_WARNING 编译时警告(非致命性错)
; 256 E_USER_ERROR 用户自定义的致命错误
; 512 E_USER_WARNING 用户自定义的警告(非致命性错误)
; 1024 E_USER_NOTICE 用户自定义的提醒(经常是bug,也可能是有意的)
; 2048 E_STRICT 编码标准化警告(建议如何修改以向前兼容)
; 4096 E_RECOVERABLE_ERROR 接近致命的运行时错误,若未被捕获则视同E_ERROR
; 6143 E_ALL 除E_STRICT外的所有错误(PHP6中为8191,即包含所有)
本文链接http://www.cxybl.com/html/wlbc/Php/20120720/31927.html



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment