0

I'm designing a page involving selecting components, however, with some components the customer just chooses not to buy anything from there. This means that one section of check boxes in the has no value assigned to it. Upon submission, this brings up the error

"Notice: Undefined index: undefined_index in D:\fileroot\page.php on line 300."

Is there any way to hide this?

NexunTech
  • 5
  • 2
  • Isn't it better just to hide those checkboxes which don't have any value? Or uncheck them and disable them? – Tjekkles Oct 06 '11 at 12:33

1 Answers1

0

Either:

error_reporting(E_ALL ^ E_NOTICE);

Or an @ before the statement containing the variable.

Or checking if(isset($variable)) before trying to acces it.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Don't turn off error reporting, that will hide things you may need. Use `isset`. – Quentin Oct 06 '11 at 12:45
  • Thanks a lot, adding the @ did it for me. – NexunTech Oct 06 '11 at 12:46
  • 1
    -1 Even though it technically works it promotes a very bad practice. Don't suppress errors. Prevent them with control structures. – Mike B Oct 06 '11 at 12:46
  • So... -1 for just one of the three options being bad? – Niet the Dark Absol Oct 06 '11 at 13:53
  • @Kolink 2 of the three. Turning of errors is just as bad as using the error suppressor. And the fact that you lead with those two without explaining the consequences or repercussions. I know that's been the *go-to* answer for so long but that's part of the reason PHP gets a bad rap. I think the quality of PHP answers on stack overflow should exceed that of the norm. You'll see this on every other 'how do I fix xxx error in php?' question when someone says "*just turn off errors*" – Mike B Oct 06 '11 at 14:22
  • There's no shortage of examples on this issue http://stackoverflow.com/questions/7059393/php-notice-supression-only-certain-circumstances-methods. – Mike B Oct 06 '11 at 14:30