Jump to content

[SOLVED] Undefined Index Issues


N-Bomb(Nerd)

Recommended Posts

I'm using an array to help with my error output on my website.. however I keep getting:

Notice: Undefined index: (value here) in script.php on line 46

 

every time I add something to the array.. I mean the script works fine.. but is there a way to hide it from showing that error message?

Link to comment
https://forums.phpfreaks.com/topic/176537-solved-undefined-index-issues/
Share on other sites

but is there a way to hide it from showing that error message?

 

Yes, but its much better to fix the error in your code.

 

The error basically means that the index you are trying to access doesn't exist within the array. You should check for its existence before trying to use it.

but is there a way to hide it from showing that error message?

 

Yes, but its much better to fix the error in your code.

 

The error basically means that the index you are trying to access doesn't exist within the array. You should check for its existence before trying to use it.

 

That's the thing, it doesn't exist yet.. I'm trying to create/add something to it right on the spot and that's when I get that.

 

I'm using the following to create the array:

$this->error[$section][] .= $error;

So the array shouldn't exist at all unless there is an error.. I only get that message when there is an error and it creates the key :confused:

 

I'm confused :(

 

You could use isset() before that to make sure that it exists.

 

also when using [] it adds a new array element on to the array, so there is no need to do .= as it will be empty.

 

Also do a print_r() on $selection and $this->error to make sure thet selection is what you think it is, and that error contains that value.

You could use isset() before that to make sure that it exists.

 

also when using [] it adds a new array element on to the array, so there is no need to do .= as it will be empty.

 

Basically I'm getting a lot of user input and there's room for user error... basically there's a set amount of sections so far that I'm using.. each could have many errors at one time. So basically I wanted to keep the array like the following:

 

Array ( 
[section1] => Array ( 
	[0] => some random error
	[1] => ohh another random error
)

[section2] => Array ( 
	[0] => your terrible
	[1] => more error
)
)

 

That way when I display all the errors to user it's a bit easier for me to sort through and show exactly where their error was at.. basically my way of thinking to keep things a bit more organized. I've only figured out how to do this by adding the extra "[]" on the end.. so I've stuck with it.

 

I don't see why I'm getting that error though.. of course it doesn't exist as I'm trying to create it.

 

What should I do?  :'(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.