undefined php Notice: Undefined index error message solution

WBOY
Release: 2016-07-29 08:43:35
Original
1199 people have browsed it

The first method: If it does not affect the normal execution of the program, you can use the shielding method
You can add
error_reporting(E_ALL ^ ​​E_NOTICE);
Turn off the NOTICE error warning in the first line of the code
The second method: Positioning Go to the specific line and solve it according to the prompts.
For example, elseif ($_POST['istrue'] == 'ok'), as shown in the above code, does not submit istrue, so there must be a problem.
It can be solved with the following code
First judge the above

Copy the code The code is as follows:


if(array_key_exists( 'istrue',$_POST))
{
if($_POST[ 'istrue'])
{
$istrue=$_POST[ 'istrue'];
}
}else{
$istrue='';
}


The subsequent judgment can be as follows

Copy the code The code is as follows:


elseif ($istrue == 'ok')


can avoid such errors. You can refer to how the system of some programs is done.
For details, please refer to the code of dedecms and phpcms

Copy the code The code is as follows:


//Check and register externally submitted variables
foreach($_REQUEST as $_k=>$_v)
{
if( strlen($_k)>0 && eregi('^(cfg_|GLOBALS)',$_k) )
{
exit('Request var not allow!');
}
}
function _RunMagicQuotes(&$ svar)
{
if(!get_magic_quotes_gpc())
{
if( is_array($svar) )
{
foreach($svar as $_k => $_v) $svar[$_k] = _RunMagicQuotes($_v );
}
else
{
$svar = addslashes($svar);
}
}
return $svar;
}
foreach(Array('_GET','_POST','_COOKIE') as $_request)
{
foreach($$_request as $_k => $_v) ${$_k} = _RunMagicQuotes($_v);
}
if(empty($istrue))
{
$istrue = '';
}

The above introduces the solution to the undefined php Notice: Undefined index error message, including the undefined content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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