PHP hints undefined index of several solutions _php skills

Source: Internet
Author: User
Tags form post parse error

Usually use $_post['],$_get['] to get the parameters in the form will appear Notice: Undefined index:--------;

We often receive the form POST 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 ... And so on some of these tips

These are the PHP prompts instead of the error, PHP itself does not need to declare the variable in advance can be used directly, but not declared variables will be prompted. Generally as a formal website will turn off the prompts, and even the error message is turned off.

Workaround:

Method 1: Server Configuration modification
To modify the error display in php.ini: Change the 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: Before the notice code appears, add @,@ to indicate that there are errors or warnings not to output, @ $username =$_post[' username '];
Precede the variable with a @, as if (@$_get[' action ']== ' save ') {...

Method 5: The last one is very practical, is a function written by someone else, through this function to pass the value.

Define a function:

Copy Code code as follows:

function _get ($STR) {
$val =!empty ($_get[$str])? $_get[$STR]: null;
return $val;
}


Then use the _get (' str ') instead of the $_get[' str ' on the line ~

[Php-core-error]

error_reporting = E_all & ~e_notice
; The error reporting level is a bit-field overlay, recommended for use with E_all | E_strict
; 1 E_error Fatal Run-time Error
; 2 e_warning Runtime Warning (non-fatal error)
; 4 E_parse Compile-time parse error
; 8 E_notice Runtime Reminders (often bugs or intentional)
; E_core_error fatal error during initialization during PHP startup
; E_core_warning warning during initialization of PHP (non-fatal error)
; E_compile_error compile-time fatal error
; 128 E_compile_warning Compile-time warning (non-fatal error)
; 256 e_user_error user-defined fatal error
; E_user_warning user-defined warning (non-fatal error)
; 1024 E_user_notice user-defined reminders (often bugs, possibly intentional)
; 2048 E_strict Coding Standardization Warning (recommended how to modify to forward compatible)
; 4096 E_recoverable_error is close to fatal run-time error and is treated as if not captured E_error
; 6143 e_all All errors except E_strict (8191 in PHP6, including all)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.