Page 1 of 1

Undefined index option error in a line with $_GET['option']

Posted: Wed Oct 15, 2003 3:55 am
by javmig
I get An Undefined index option error in this line

if ($_GET['option']) { something to write in the output }

this happens when the parameter is not passed in the GET request.

I use php 4.3.3

In older versions of php I think that this error didn't happen.

How can I solve it?

Thanks!!! :D

Posted: Wed Oct 15, 2003 3:59 am
by twigletmac
The error happened in your old versions of PHP, you just had error reporting set low so that you didn't see the error message.

To fix this you need to test for the existance of variables using isset() or empty() (check the manual for the difference between the two). For example, if you used isset() you would have:

Code: Select all

if (isset($_GET['option'])) {
instead of

Code: Select all

if ($_GET['option']) {
and if you used empty() you would have:

Code: Select all

if (!empty($_GET['option'])) {
Mac