Krishna Srinivasan wrote:
I have a form with check boxes. When accessing a check box element
that is not checked, I get a notice (Notice: Undefined variable..). Is
there a way to hide these notices and warning in PHP code without
having to modify the PHP.ini file?
Krishna Srinivasan.
I'd suggest not suppressing the error and rather changing your code to
account for the fact that someone may not check a given box on your
form. The undefined variable notice is much like a compiler warning in
C/C++. Unfortunately, the programmers I deal with in C/C++ ignore the
errors much like you're trying to suppress the PHP notice, which usually
ends up in some type of error further down the road.
Instead, I'd suggest checking for the value before attempting to use it:
if(isset($_POST['var_name']))//User checked the box (sub $_GET if req'd)
{
// Do whatever...
}
else // User didn't check the box
{
// Do whatever... lose the else block if you need to do nothing
}
Any PHP project I manage the first rule is, warnings/notices are errors.
I only allow the suppression of warnings when the warning is dealt
with in the code (for example, I'll usually suppress the warnings from
fopen since my code explicitly deals with failures).
HTH,
Derek