40esp Posted June 19, 2008 Share Posted June 19, 2008 Im trying to get a form validation script to work: <?php if ((isset($_POST['add_email']) && ($_POST['add_email'] == "")) || ((isset($_POST['select'])) && ($_POST['select'] == ""))) { exit(); } else { echo "fgfgdfgdgdfgdfg"; } ?> The problem is, $_POST['add_email'] can be filled with an email address, and $_POST['select'] could be blank, and it will still process echo "fgfgdfgdgdfgdfg";. even though I've said check $_POST['select'] in my if statement.. its like its completely ignoring the first part of the script. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/ Share on other sites More sharing options...
MatthewJ Posted June 19, 2008 Share Posted June 19, 2008 You should post the form Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569260 Share on other sites More sharing options...
ober Posted June 19, 2008 Share Posted June 19, 2008 Throw print_r($_POST); in front of all of that and verify your values. My guess is that it isn't what you're expecting. Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569262 Share on other sites More sharing options...
lemmin Posted June 19, 2008 Share Posted June 19, 2008 It is because you are using the OR operator. You are basically only asking that one OR the other is filled in. Simply change "||" to "&&" and it will check both. Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569267 Share on other sites More sharing options...
abdfahim Posted June 19, 2008 Share Posted June 19, 2008 I would rather go like this if (isset($_POST['submit_button_name'])){ if (trim($_POST['add_email']) == "" or trim($_POST['select']) == "") { exit(); }else{ echo "done"; } } Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569273 Share on other sites More sharing options...
abdfahim Posted June 19, 2008 Share Posted June 19, 2008 hi lemmin .. he wants to exit if either email or select field is blank ... so he should OR this, not AND. If he change OR to AND as you said, it'll exit only if both email and select field is blank, which is not the thing he wants, I guess. Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569275 Share on other sites More sharing options...
40esp Posted June 19, 2008 Author Share Posted June 19, 2008 I got it, Thanks for the help! The print_r($_POST); helped. Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569277 Share on other sites More sharing options...
ober Posted June 19, 2008 Share Posted June 19, 2008 It is because you are using the OR operator. You are basically only asking that one OR the other is filled in. Simply change "||" to "&&" and it will check both. Wrong. He wants to bail if either meets the criteria. For your scenario, both would have to fail. Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569278 Share on other sites More sharing options...
lemmin Posted June 19, 2008 Share Posted June 19, 2008 Woops, sorry. I saw those as "if not equal" at first glance. Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569283 Share on other sites More sharing options...
abdfahim Posted June 19, 2008 Share Posted June 19, 2008 nice to see your problem solved, but remember to use TRIM() function in such case, otherwise if any blank space is there in any field, you will be bluffed. Quote Link to comment https://forums.phpfreaks.com/topic/110961-solved-form-validation/#findComment-569284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.