Please Help me "Notice: Undefined index"

General discussion on PHP

Please Help me "Notice: Undefined index"

Postby tklinn on Wed Apr 22, 2009 4:54 am

I got the errors what is does mean?

Notice: Undefined index: BILL_STATUS in E:\edit_bookings.php on line 103
Thanks & Best Regards,
Thet Kyaw Linn
Posts: 17
Joined: Mon Mar 30, 2009 8:30 am
Location: Singapore

Re: Please Help me "Notice: Undefined index"

Postby gregor171 on Wed Apr 22, 2009 12:53 pm

Post a few liner around that if this won't help.

It might have somthing to do with you calling index from array that is not there.
Code: Select all
$xvar = $myvar['BILL_STATUS'];

will make such Notice (it's not an error). However it might make some overhead, so to prevent this:
Code: Select all
if (isset($myvar['BILL_STATUS'])){
$xvar = $myvar['BILL_STATUS'];
Gregor Grajzar, web developer
Posts: 6
Joined: Wed Apr 22, 2009 12:25 pm

Re: Please Help me "Notice: Undefined index"

Postby ericritchie on Fri Apr 24, 2009 10:53 am

Hi Thet,

As Gregor pointed out you could check for the existence of the array key, but this would negate one of the key advantages of PHP in that you can use variables without initalisation which in controlled conditions can be exceptionally useful.

The warning is there to inform you that you are using an uninitalised variable, which can be a security threat. If you are know where the data in $myvar comes from, or have a non public enviroment, you can simply turn of notices altogether. You can do this in your php.ini file or my adding the following line to the top of your code:

Code: Select all
ini_set('error_reporting', 'E_ALL & ~E_NOTICE');

Eric Ritchie
User avatar
Posts: 118
Joined: Tue Feb 10, 2009 10:09 am

Re: Please Help me "Notice: Undefined index"

Postby rasu_79 on Fri Mar 23, 2012 9:15 am

If you don't want to change the settings thru ini_set() or in php.ini file, u can place '@' character in front of the variable causes the notice to render.
Posts: 1
Joined: Mon Nov 15, 2010 9:50 am

Return to PHP

Who is online

Users browsing this forum: No registered users and 4 guests