If a user enters in (YES/NO/Don't know) I want code to continue testing if they enter in anything else I want the error message to appear. My code below isn't working: elseif ($hosting != "Yes" || $hosting != "No" || $hosting != "Don't know") { echo "Error......."; } PHP: Can anyone advise. Thanks Ian
You should then use AND instead of OR. This way if Any of the 3 tests fails, meaning YES/NO/DON'T KNOW is found, it will not fall into the error. Like this: elseif ($hosting != "Yes" && $hosting != "No" && $hosting != "Don't know") { echo "Error......."; } PHP:
Thanks works a treat, i also did the following more complicated route which worked.... function validate_hosting($a) { $forbidden = array('Yes', 'No', 'Do not know'); foreach ($forbidden as $b) if (strpos($a, $b) !== false) return true; return false; } elseif (!validate_hosting($_POST['hosting'])) { echo "Sorry you are trying to alter the'Do you require hosting field' which you have no access to"; } PHP: Ian
If you're using a select box for "Yes","No", and "Do not know", you could simply do this then: $forbidden = array('Yes', 'No', 'Do not know'); function validate_hosting($a) { global $forbidden; return in_array($a,$forbidden); } PHP: No messy foreach loop
Thanks for that, yes do have combo drop down and want to make sure I don't get hit by bots, hence going OTT in checking everything. Ian