N-Bomb(Nerd) Posted October 5, 2009 Share Posted October 5, 2009 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 More sharing options...
trq Posted October 5, 2009 Share Posted October 5, 2009 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. Link to comment https://forums.phpfreaks.com/topic/176537-solved-undefined-index-issues/#findComment-930577 Share on other sites More sharing options...
N-Bomb(Nerd) Posted October 5, 2009 Author Share Posted October 5, 2009 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 I'm confused Link to comment https://forums.phpfreaks.com/topic/176537-solved-undefined-index-issues/#findComment-930587 Share on other sites More sharing options...
Jibberish Posted October 5, 2009 Share Posted October 5, 2009 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. Link to comment https://forums.phpfreaks.com/topic/176537-solved-undefined-index-issues/#findComment-930591 Share on other sites More sharing options...
N-Bomb(Nerd) Posted October 5, 2009 Author Share Posted October 5, 2009 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? :'( Link to comment https://forums.phpfreaks.com/topic/176537-solved-undefined-index-issues/#findComment-930594 Share on other sites More sharing options...
trq Posted October 5, 2009 Share Posted October 5, 2009 Use = instead of .= Link to comment https://forums.phpfreaks.com/topic/176537-solved-undefined-index-issues/#findComment-930598 Share on other sites More sharing options...
N-Bomb(Nerd) Posted October 5, 2009 Author Share Posted October 5, 2009 Use = instead of .= That's just about a bitch.. Thanks. Link to comment https://forums.phpfreaks.com/topic/176537-solved-undefined-index-issues/#findComment-930599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.