Home > Article > Backend Development > Solutions to php Undefined index and Undefined variable_PHP tutorial
$act=$_POST['act'];
Using the above code always prompts
Notice: Undefined index: act in F:windsflybookpost.php on line 18
In addition, sometimes There will also be
reference content
Notice: Undefined variable: Submit...
and other such prompts
Cause: caused by the variable being undefined
Solution:
1) error_reporting setting:
Find error_reporting = E_ALL
Change to error_reporting = E_ALL & ~E_NOTICE
2) register_globals setting:
Find register_globals = Off
and change it 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 you do if this happens? What?
Just find the
of php.ini in C:WINDOWS. In php.ini, line 302 error_reporting = E_ALL
and change it to
error_reporting = E_ALL & ~E_NOTICE and then restart apache2.2.
Solution: Modify php.ini
Change: error_reporting = E_ALL
to: error_reporting = E_ALL & ~E_NOTICE
If you don’t want any errors to be displayed, directly modify:
display_errors = Off
If you do not have permission to modify php.ini, you can add
ini_set("error_reporting", "E_ALL & ~E_NOTICE");
to the php header.