Forum Moderators: coopster
Notice: Undefined index: username in *LOCATION* on line 79
Notice: Undefined index: id in *LOCATION* on line 80
Notice: Undefined index: username in *LOCATION* on line 83
Notice: Undefined index: username in *LOCATION* on line 124
Notice: Undefined index: id in *LOCATION* on line 164
ok oviously I edited out the location for privay issues but thats besides the point. Now much if not all these errors come up because they operate off of sub categories like $id=$_REQUEST['id']; and if( $_REQUEST['id'])
either way its not disrupting my work but it seems very anoying to have such things show; I dont know if this would be an issue of PHP being too sensative, or if APACHE would be too sensative .. but if someone knows how to ignore irrelevent messages like this, yeh help plz.
The best strategy is to correct your code so you don't get notices.
The notice in question refers to an array index. You are perhaps doing something like
if ($var['idx'])
If you have not assigned a value to $var['idx'], then the index is undefined. You have two choices:
1. assign default values to variables
$var['idx'] = "";
if ($var['idx'}
2. test variables
if (isset($var['idx'] && $var['idx'])
You get no error because if the first part is false, it stops.
If you don't like that solution and want to suppress these notices, you must change the "error handling and logging" settings in your php.ini file.
You could have PHP simply not report notices:
error_reporting = E_ALL & ~E_NOTICE
If be it possible to turn off the SPECIFIC messages of Undefined Index and Undefined Variable . . that would be nice. I will start going back and weaking what I can so they dont become notices as suggested . . but I'd rather not have to waste time doing that.
You could have PHP simply not report notices:
error_reporting = E_ALL & ~E_NOTICE
or read here
error_reporting [ca.php.net]
but I'd rather not have to waste time doing that.
That's my point. You are not wasting time. You have undefined indexes and undefined variables, which you should get rid of.
See message #6 by coopster in this thread
[webmasterworld.com...]
If you get in the habit of running with error reporting set to E_ALL, it won't take you more time, it will take you less time?
Why? Because the notices and warnings flag potential trouble spots in your code. It's sort of like setting "Option Explicit" in Visual Basic. Yes, it can cause problems for your code, but it avoids more problems than it causes.
For me, my development server will always be set to E_ALL, and no production server ever will be unless it sends errors to somewhere other than the screen.
I was just trying to tell you why it was happening, give you two options to fix it (change the code or change the error reporting) and to try t convince you to choose #1.
Ultimately your choice. I know coopster and I (and many others here) choose #1, don't know about Jatar_K.
Another thread on the topic (same people shooting their mouths.. er fingers off, though):
[webmasterworld.com...]
That's sort of what I meant by #1 (go with all and fix the code so you don't get errors). So I'll put you down for #1 too.
It has occurred to me that your solution is the best (always report all, but log them instead of sending them to the screen), but I haven't done it (for some reason I thought error reporting settings were PHP_INI_SYSTEM, not PHP_INI_ALL and could therefore only be changed where you had access to php.ini, which is not usually my case).
That's what I was thinking and alluding to in the last post. However, since you can set the
- error log file path
- max length of the log in bytes
- and you can set it from .htaccess or even at runtime [us2.php.net]
it doesn't seem like there is any real inconvenience. Then if someone tells you there's a problem with the script, you can ftp the error log. Seems like a good idea.