Home  >  Article  >  Backend Development  >  Solutions to Undefined index and Undefined variable appearing in php

Solutions to Undefined index and Undefined variable appearing in php

WBOY
WBOYOriginal
2016-07-25 09:10:19954browse
This prompt always appears during the PHP project. At first, $act was used to accept the data posted from the form: $act=$_POST['act'];

This prompt always appears during the PHP project. At first, $act was used to accept the data posted from the form: $act=$_POST['act'];

Using the above code always prompts: Notice: Undefined index: act in F:windsflybookpost.php on line 18

In addition, sometimes: Notice: Undefined variable: Submit...and other such prompts.

Cause: Caused by undefined variables

Solution: 1) error_reporting settings: Find error_reporting = E_ALL Modify to error_reporting = E_ALL & ~E_NOTICE

2) register_globals settings: Find register_globals = Off Modify to 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 ........ Originally, PHP does not need to define variables, but what should we do if this happens? Just find php.ini in C:WINDOWS In php.ini, line 302 error_reporting = E_ALL changed to error_reporting = E_ALL & ~E_NOTICE and then restart apache2.2. Solution: modify php.ini Change: error_reporting = E_ALL Modify to: error_reporting = E_ALL & ~E_NOTICE If you don’t want any errors to be displayed, modify them directly: display_errors = Off If you do not have permission to modify php.ini, you can add it in the php header ini_set("error_reporting","E_ALL & ~E_NOTICE"); That’s it



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