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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
javmig
Forum Newbie
Posts: 2
Joined: Wed Oct 15, 2003 3:55 am

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

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply