CBaZ Posted March 1, 2013 Share Posted March 1, 2013 I have this simple script I started but for some reason it doesn't continue even if the right answer is given. Also how would I go about adding multiple questions? <?php //simple captcha if(isset($_POST['answer']) && $_POST['answer']!='') { echo "<script>alert('You provided a wrong answer for the Security Question')</script>"; echo "<a href='cabbie.php'>Please return to the Form and try again.</a><br /><br />\n"; exit; } else if(isset($_POST['answer']) && $_POST['answer']!='blue') { //This is the problem script above of course my code continues here. Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/ Share on other sites More sharing options...
requinix Posted March 1, 2013 Share Posted March 1, 2013 Looks like the answer is "blue"? Take a look at what you wrote: isset($_POST['answer']) && $_POST['answer']!=''Say I enter "blue". Is the answer isset()? Yes. Is the answer not empty? Yes. Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415917 Share on other sites More sharing options...
CBaZ Posted March 2, 2013 Author Share Posted March 2, 2013 ok what am I missing here? Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415924 Share on other sites More sharing options...
requinix Posted March 2, 2013 Share Posted March 2, 2013 That entering anything at all as the answer will trigger that branch to execute. Given that the message is about entering the wrong answer, shouldn't the condition check to see if you entered the wrong answer? Hint: you do it a couple lines lower. Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415929 Share on other sites More sharing options...
CBaZ Posted March 2, 2013 Author Share Posted March 2, 2013 ok the real thing i am missing is what to do if its actually set to the correct answer I am not doing. Am I seeing this correctly now? Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415935 Share on other sites More sharing options...
requinix Posted March 2, 2013 Share Posted March 2, 2013 If you do enter the right password then, with the correct code, the answer will be isset() but it won't not-match the answer (ie, it does equal the answer) and the branch won't execute. Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415940 Share on other sites More sharing options...
CBaZ Posted March 2, 2013 Author Share Posted March 2, 2013 totally confused now lol. Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415942 Share on other sites More sharing options...
requinix Posted March 2, 2013 Share Posted March 2, 2013 Bad: if(isset($_POST['answer']) && $_POST['answer']!='') { Good: if(isset($_POST['answer']) && $_POST['answer']!='blue') { Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415946 Share on other sites More sharing options...
ignace Posted March 2, 2013 Share Posted March 2, 2013 (edited) if (isset($_POST['answer'])) { // user posted something.. can be anything at this point (except null) if ($_POST['answer'] == 'blue') { // he posted blue } elseif ($_POST['answer'] == '') { // he just submitted the form without entering anything (show the form) } else { // he entered something other then blue or empty (show the form) echo $_POST['answer'] === 'pink' ? 'You silver-tongued devil you!' : $_POST['answer'] . ' is not correct'; } } Edited March 2, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/275102-security-question-problem/#findComment-1415966 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.