Jump to content


Photo

How to fix "undefined index: variable_name" error?


  • Please log in to reply
2 replies to this topic

#1 hstraf

hstraf
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 June 2006 - 02:50 PM

Hello,

I need some help to diagnose and determine what is causing this problem and (most importantly) how to correct it.

Here is the error.  (I get a whole bunch just like this.. always the "undefined index: variable_name"

PHP Notice:  Undefined index:  pasv in C:\xxx_path_xxx\domain.org\zzzzz\autoinstaller.php on line 87


Here is the code on line 87:

if ($_GET['pasv'] == "on") { $_SESSION['ftp_passive'] = "on"; }

I believe the php error is caused because php is trying to "use" an undefined variable (called pasv) for the first time, and the php config is somehow set to produce this warning.

This is becoming more and more common to see now, and it seems to happen when my users have to re-install PHP.  So I think there is some setting in a more recent "default' php installation which is causing this.

Does anyone have any idea what setting or configuration value can be set in PHP to "turn off" this warning?  (I tried setting the error_reporting(0); but that did not stop it.)

Or must I rewrite my entire PHP program to "declare" all variable before they are used?

Thanks for any help. 


#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 30 June 2006 - 02:53 PM

The problem is coming from the fact that you're requesting the [blah] value from the $_GET array, when there is no [blah] value you set.  If you want to avoid this error, which I believe isn't fatal and with the right error settings wouldn't display (ie production settings), then you should do the following:
if (isset($_GET[blah])) {
// do some stuff with the blah value
} else {
// maybe set blah?
}

Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 hstraf

hstraf
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 June 2006 - 03:12 PM

Thanks very much!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users