PHP Notice: Undefined index

Have you ever gotten this error:
Notice: Undefined index ‘fields of the table’ in ‘path of the PHP file you’re executing’ on line ‘the current linenumber’ ? I think you do, since most probably, Google or Bing or so have lead you to this post because you were searching for a solution for that very errormessage :-)
Well, you get this error when using $ _POST or $ _GET variables to retrieve the data from a form, and the variables are not set.

To get rid of this error, it is sufficient to test if the field of the table was initialized with the function isset ().[ad#r]

// Check this before you start using your $_POST['value'] variable
if (isset($_POST['value']))
{
// Use and abuse your $_POST['value'] here!
}

Another way to get rid of this error, is by changing the configuration of your Apache/PHP setup. The error above is considered a minor error, corresponding to the constant E_NOTICE, and thus not shown in the standard configuration. You can set your error reporting level in your PHP scripts with the error_reporting function, and by using these constants:
E_WARNING     Non-fatal run-time errors. Execution of the script is not halted
E_NOTICE     Run-time notices. The script found something that might be an error, but could also happen when running a script normally
E_RECOVERABLE_ERROR     Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle
E_ALL
Errorlevels can be combined in the error_reporting function such as E_ALL^E_NOTICE, which would show all errors, except Notices.

Incoming search terms:


One Response to “PHP Notice: Undefined index”

  1. Ogundipe Anthony - http://www.dhtmlextreme.net/ says:

    Fantastic PHP tutorial, i love this.

Leave a Reply

CommentLuv badge