How to solve the problem of undefined index in php
Although this prompt can be hidden by setting the error display mode, this also has hidden dangers, that is, these prompts will be recorded in the server's log, causing the log file to be abnormally large.
Usually use $_post[''] ,$_get[''] will appear when getting the parameters in the formNotice: Undefined index: --------;
We often receive POST from the form The data reports an Undefined index error, as follows: $act=$_POST['action'];
Using the above code always prompts
Notice: Undefined index: act in D:\test\post.php on line 20
In addition, sometimes
Notice: Undefined variable: Submit...and other such prompts will appear
The above are PHP prompts rather than errors. PHP itself does not need to declare variables in advance. It can be used directly, but there will be a prompt for undeclared variables. Generally, as a formal website, prompts will be turned off, and even error messages will be turned off.
Solution:
Method 1: Server configuration modification
Modify the error display mode under the error configuration in php.ini: Modify error_reporting = E_ALL to
error_reporting = E_ALL & ~E_NOTICE
Restart the APCHE server after modification to take effect.
Method 2: Initialize variables.
Method 3: Make judgment isset($_post['']), empty($_post['']) if --else
Method 4: Add @ before the notice code appears, @ represents this line Do not output if there is an error or warning, @$username=$_post['username'];
Add an @ in front of the variable, such as if (@$_GET['action']=='save') { . ..
Method 5: The last method is very practical. It is a function written by others, and the value is transferred through this function.
Define a function:
function _get($str){ $val = !empty($_GET[$str]) ? $_GET[$str] : null; return $val; }
Then when using it, just use _get('str') instead of $_GET['str']~
[PHP-Core-Error]
error_reporting = E_ALL & ~E_NOTICE
; The error reporting level is the superposition of bit fields. It is recommended to use E_ALL | E_STRICT
; 1 E_ERROR fatal runtime error
; 2 E_WARNING runtime warning (non-fatal sexual error)
; 4 E_PARSE Compile-time parsing error
; 8 E_NOTICE Run-time reminder (often a bug, may be intentional)
; 16 E_CORE_ERROR Fatal error during PHP startup initialization process
; 32 E_CORE_WARNING Warning during PHP startup initialization process (non-fatal error)
; 64 E_COMPILE_ERROR Fatal error during compilation
; 128 E_COMPILE_WARNING Warning during compilation (non-fatal error)
; 256 E_USER_ERROR User-defined fatal error
; 512 E_USER_WARNING User-defined warning (non-fatal error)
; 1024 E_USER_NOTICE User-defined reminder (often a bug, may also be intentional)
; 2048 E_STRICT encoding standardization warning (recommended how to modify for forward compatibility)
; 4096 E_RECOVERABLE_ERROR A near-fatal runtime error, if not caught, it will be treated as E_ERROR
; 6143 E_ALL All errors except E_STRICT (in PHP6 8191, that is, including all)
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Use strip_tags() in php to remove html tags and still have blank solutions
##Use PHP How to get the real IP of the user client
The above is the detailed content of How to solve the problem of undefined index in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: <

When writing code in PHP, we may encounter the error message "Notice: Undefinedproperty". This error means that we are accessing an undefined property, usually because the property has not been initialized in the code. So, how to solve this problem? Here are a few possible solutions: Initialize properties This is the simplest way to solve this problem. Explicitly initializing a property in code ensures that it is defined before use. For example: class

If you often encounter the error message "TypeError: Cannotreadproperty'$XXX'ofundefined" when developing with Vue.js, how should you deal with it? This article explains the causes of this error and how to fix it. The cause of the problem is that when using Vue.js, we often use this to call methods of Vue components, such as: exportdefault{data()

In JavaScript, both undefined and null represent the concept of "nothing": 1. undefined represents an uninitialized variable or a non-existent property. When a variable is declared but no value is assigned to it, the value of the variable is undefined , when accessing properties that do not exist in the object, the returned value is also undefined; 2. null represents an empty object reference. In some cases, the object reference can be set to null to release the memory it occupies.

In the Go language, the path package is one of the important tools for processing file paths. The path.Join() function can combine multiple paths into a complete path. However, sometimes you will encounter the error message "undefined: path.Join", what should you do? Here are several common solutions: Check the import statement First, you need to confirm that you have imported the path package correctly. In Go language, when importing a package, you can

The difference between null and undefined is: 1. Semantic meaning; 2. Usage scenarios; 3. Comparison with other values; 4. Relationship with global variables; 5. Relationship with function parameters; 6. Nullability check; 7. Performance considerations; 8. Performance in JSON serialization; 9. Relationship with types. Detailed introduction: 1. Semantic meaning, null usually means knowing that this variable will not have any valid object value, while undefined usually means that the variable has not been assigned a value, or the object does not have this attribute; 2. Usage scenarios, etc.

Both null and undefined indicate a lack of value or an undefined state. Depending on the usage scenario, there are some guiding principles for choosing to use null or undefined: 1. When you need to clearly indicate that a variable is empty or invalid, you can use null; 2. When a variable has been declared but not yet assigned a value, it will be set to undefined by default; 3. When you need to check whether a variable is empty or undefined, use the strict equality operator "===" to determine whether the variable is null or undefined. .

undefined represents a state in which a value or variable does not exist or is undefined. It can be used as a default value to determine whether a variable has been assigned a value, and can also be used to set default parameter values. Although undefined may have different meanings and usages in different programming languages, understanding the concept of undefined can help us better understand and write programs.
