Hugh Beaumont wrote:
I've been working with
error_reporting(E_ALL)
set lately trying to write code that does not give notices or errors.
I have not been able to solve the following:
given a form with a checkbox that may or may not be set, we'll call it "exact" as in
<input type = "checkbox" name = "exact">
the following code outputs :
Notice: Undefined index: exact in search.php on line 10
code :
if (!isset($_POST['exact'])) { <--------- line 10
$_POST['exact'] == false;
}
if ($_POST['exact'] == "checked") <------ also here
{
$exact_match_only = true;
}
else {
$exact_match_only = false;
}
I understand why it is giving the notice but I'm not sure how to make it stop.
What is the proper way to set a variable so that it's non-existance will not generate
a notice?
Any ideas?
Let me know if the above is not clear. Thanks.
Try it like this...
if ( isset ( $_POST['exact'] ) ) {
// do what you need to do if it's checked
} else {
// do what you need to do if it's not checked
}
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@xxxxxxxxxxxx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php