Home > Backend Development > PHP Tutorial > Notice: undefined index.. Error prompt solution_PHP tutorial

Notice: undefined index.. Error prompt solution_PHP tutorial

WBOY
Release: 2016-07-13 10:55:45
Original
1364 people have browsed it

This sentence is about some problems that will be encountered in PHP development. Looking at this prompt, we all know that the variable is undefined, so let’s solve the Notice: undefined index method.

First, because the variable is undefined, we only need to Find relevant location plus

The code is as follows
 代码如下 复制代码

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

isset($_GET['你的变量'])?$_GET['你的变量']:'';

Copy code

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

return $val;
 代码如下 复制代码

if (!$cfg['debug']) {
 error_reporting(0);
 ob_start('ob_gzhandler');
} else {
 error_reporting(E_ALL ^ E_NOTICE);
}

}

or


isset($_GET['your variable'])?$_GET['your variable']:'';


We only mentioned the usage of get above. The same is true for post. Just change the get above to post.

There is also a global definition method for the program

error_reporting(0); ob_start('ob_gzhandler');
The code is as follows Copy code


if (!$cfg['debug']) {
} else { error_reporting(E_ALL ^ ​​E_NOTICE);

}

In this way, we only need to set the variable debug to 0 or 1 to switch the error prompt on and off Methods provided by other web pages Method 1: Server configuration modification
Modify the php.ini configuration file, error_reporting = E_ALL & ~E_NOTICE
Method 2: Add @ before the notice code appears. @ indicates that there is an error in this line or a warning not to output, @$username=$_post['username'];
Note: If you are using global definitions or modifying the php.ini configuration file so that all error prompts will not appear, this will be quite troublesome for development and testing. The best way to use the program is to turn off the error prompts. Set up on the server. http://www.bkjia.com/PHPjc/632213.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632213.htmlTechArticleThis sentence is about some problems that will be encountered in PHP development. Looking at this prompt, we all know that the variable is undefined. Then let’s solve the Notice: undefined index method. 1. This is because the variable is undefined...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template