Monday, 24 November 2014

PHP - Notice: Undefined index

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 theerror_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.

0 comments:

Post a Comment