Xtremer360 Posted June 17, 2011 Share Posted June 17, 2011 I'm not sure why but when i submit the form it's not returning an error when there is NOT a selection made to my questions select box OR if there not an answer given to the answer text box and not sure why. http://pastebin.com/PeurLUt2 Quote Link to comment https://forums.phpfreaks.com/topic/239677-not-showing-error-is-no-input-is-given/ Share on other sites More sharing options...
Xtremer360 Posted June 17, 2011 Author Share Posted June 17, 2011 I've tried numerous things and I am not having any luck. Quote Link to comment https://forums.phpfreaks.com/topic/239677-not-showing-error-is-no-input-is-given/#findComment-1231230 Share on other sites More sharing options...
xyph Posted June 17, 2011 Share Posted June 17, 2011 For one, you'll allowing the script to continue running even after a fatal error. Take this example <?php $foo = 'no'; $bar = 'yes'; if( $foo == 'no' ) echo 'Fatal error!'; if( $bar == 'yes' ) echo 'Things are working as expected'; ?> Will output Fatal error!Things are working as expected While <?php $foo = 'no'; $bar = 'yes'; if( $foo == 'yes' ) { if( $bar == 'yes' ) echo 'Things are working as expected'; } else echo 'Fatal error!'; ?> outputs Fatal error! This is a very basic example, and in a complex situation like yours you may have a TON of nested ifs. In this case, I would put everything into a function, then you can simply use a return to stop the function when you hit an error. <?php $foo = 'no'; $bar = 'yes'; echo checkThis( $foo, $bar ); function checkThis( $arg1, $arg2 ) { if( $arg1 != 'yes' ) return 'Error - First argument was not a yes'; if( $arg2 != 'yes' ) return 'Error - Second argument was not a yes'; return 'Both arguements were yes'; } ?> Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/239677-not-showing-error-is-no-input-is-given/#findComment-1231239 Share on other sites More sharing options...
Xtremer360 Posted June 17, 2011 Author Share Posted June 17, 2011 The hard part is implementing the idea into my already written code. The rest of the code works EXCEPT for the parts that deal with the questions and answers. Quote Link to comment https://forums.phpfreaks.com/topic/239677-not-showing-error-is-no-input-is-given/#findComment-1231242 Share on other sites More sharing options...
Xtremer360 Posted June 18, 2011 Author Share Posted June 18, 2011 What I'm trying to correct is the part that checks to see if question1 and question2 have a selection made that has a value bigger than 0 because the option value with 0 is the -select- option. Because when I fill out my registration form it bypasses the fact that there wasn't a selection made for those two dropdowns. Quote Link to comment https://forums.phpfreaks.com/topic/239677-not-showing-error-is-no-input-is-given/#findComment-1231319 Share on other sites More sharing options...
xyph Posted June 18, 2011 Share Posted June 18, 2011 Well, you're checking a ton of variables that haven't been defined, unless you're working with register_globals. Lines 51-60 create the variables you're trying to check for in lines 16-21 and lines 24 and 25. For some reason you actually check the right variables on lines 22 and 23 Quote Link to comment https://forums.phpfreaks.com/topic/239677-not-showing-error-is-no-input-is-given/#findComment-1231338 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.