Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

Undefined index error in PHP

|| 0

Undefined index error in PHP
Stechies

How to solve undefined index error in PHP?

Undefined index error in PHP can be:

Notice: Undefined index: search in C:xampphtdocsGooglesearch.php on line 23

Cause of this error:

When using special PHP functions $ _POST or $ _GET  a user may get an Undefined Index error. These special functions are used to get variables from a user-filled form. 

Notification of Undefined index error

These Undefined index errors are small or minor errors, therefore, they are not usually notified by default. But in order to get notified about these error user can change the type of error reported using the function error_reporting function.

Solution

User can avoid this error by using PHP isset ().

If order to resolve the undefined index error in PHP we just need to add

if(isset($_GET[index error name]))

Example 

To resolve above mentioned error:

Notice: Undefined index: search in C:xampphtdocsGooglesearch.php on line 23

if(isset($_GET[search])) //'search' is name of index error

 


Advertisement
Advertisement
Advertisement