Re: proper method to do the following...
| From: | John Nichel | Date: | Wed, 06 Oct 2004 14:01:01 +0000 |
| Subject: | Re: proper method to do the following... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198752@lists.php.net to get a copy of this message | ||
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@kegworks.com