When you use $_post['],$_get[' to get the parameters in the form
Notice: Undefined index:--------;
We often receive forms post over the data Times undefined index error, as follows:
$act =$_post[' action '];
Always prompt with the above code
notice:undefined index:act in D:\test\post.php on line 20
In addition, there are sometimes
Notice:undefined Variable:submit ... Wait for some of these tips
These are the PHP tips instead of an error, and PHP itself does not need to declare variables in advance to be used directly, but there are hints for undeclared variables. Generally as a formal website will be the prompt to turn off, and even the error message is also turned off.
Workaround:
Method 1: Server configuration Modifications
To modify the error display in php.ini in the errors configuration:
Modify error_reporting = E_all to error_reporting = E_all & ~e_notice
After the modification, restart the Apche server before it can take effect.
Method 2: Initialize the variable.
Method 3: Make a Judgment
Isset ($_post["]), Empty ($_post[")) if--else
Method 4: Add @,@ before the notice code to indicate that the line has errors or warnings do not output, @ $username =$_post[' username '];
Precede the variable with an @, such as if (@$_get[' action ']== ' save ') {...
Method 5: The last one is very practical, is a function written by others, through this function to pass the value.
Define a function:
The code is as follows:
function _get ($str) {$val =!empty ($_get[$str])? $_get[$STR]: null; return $val;}
Then use _get (' str ') instead of $_get[' str ').