PDA

View Full Version : How To Fix PHP Error Notice: Undefined variable: index”



Wise
05-02-15, 08:56 AM
How To Fix PHP Error Notice: Undefined variable: index”


Undefined index means that you are referencing an array index that doesn’t exist yet. It sounds like you aren’t passing header and Body as POST items.
Undefined Index is just a notice, rather than an actual error. It’s bad form, but I turn notices off in php.ini. You can try adding this to your page to see if that stops the message:

1. Open php.ini

2. Make a change to this line

Look for
error_reporting = E_ALL

comment out by adding a semicolon
;error_reporting = E_ALL
OR

replace the above line to
error_reporting = E_ALL & ~E_NOTICE

You can also supress notice errors by putting @ before the variable.

PHP Code: @$variable = $_GET['a'];

Apple
13-02-15, 03:26 AM
Nice , thanks for sharing.

adriancs35
01-06-15, 04:36 AM
Or you can actually fix those by actually takeing care if the variable is defined or not:

if (isset($_GET['a'])){
$variable = $_GET['a'];
}

This way you won't need to cheat by suppresing with '@' or disabling the error, that in my opinion can do rather bad than good when you're trying to debug.