PHP - Notice: Undefined index

January 2017

$ _POST or $ _GET are two special functions of PHP that are used to get variables from a user-filled form. While using these functions, a user may encounter an error - Notice: Undefined index. This error can be avoided with the help of PHP isset (). This error will be notified, but that depends on the configuration of the server. Notice: Undefined index is a minor error and hence not notified by default. With the help of the error_reporting function, the type of error reported can be changed.




When using $ _POST or $ _GET to retrieve the variables from a form, you may encounter this error:
Notice: Undefined index 'fields of the table' in 'path of  php file being executes' on line 'current line'     


To avoid this error, simply test whether the fields of the table were initialized with the function isset ().
// Before using $_POST['value']    
if (isset($_POST['value']))    
{    
          // Instructions if $_POST['value'] exist    
}    

This type of error is notified depending on the configuration of the server.
It is not notified by default as it is considered as a minor error, corresponding to the constant E_NOTICE.

You can change the types of errors reported with the error_reporting function.

Related


Published by jak58. Latest update on February 12, 2012 at 05:03 PM by Paul Berentzen.
This document, titled "PHP - Notice: Undefined index," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).