biblestamps Posted April 21, 2009 Share Posted April 21, 2009 Hello. I am trying to validate the "image validation code" the user has entered into my form. I have tried this several ways and it is not recognizing when the correct answer is entered. Whether you enter it incorrectly or correctly, you get the "incorrect" error message telling you to try again. This is the part of the coding causing me grief. I have tried simple "If...else" then tried "If...elseif" which is what it is now however feel free to post else if in case I had something wrong when i did it before. ($_POST[vercode] refers to what the user has entered...$_SESSION['vercode'] refers to what the code php in a different file called captcha.php) I just realized while writing this post out, that i have not told this file (snippet below) how to find the $_SESSION information...I assume that is the problem...? HOW DO I DO THAT? It knows what the $_POST is because that info is pulled into the same file as the snippet below...how do I tell it where to find the $_SESSION info that is in the captcha.php file? (I should add here even though it is probably apparent, that I am learning as I go and usually feel like I only know just enough to be dangerous. HA.) thank you very much for your time. { if ($_POST["vercode"]!=$_SESSION["vercode"] OR $_POST["vercode"]=='') echo '<strong>Incorrect verification code- use browser back button to try again.</strong><br>'; elseif ($_POST["vercode"]==$_SESSION["vercode"]) // redirect to thank you page print "<meta http-equiv=\"refresh\" content=\"0;/MYBethel/MB_thankyou.php>"; } Link to comment https://forums.phpfreaks.com/topic/155065-my-if-else-statement-not-working/ Share on other sites More sharing options...
Mchl Posted April 21, 2009 Share Posted April 21, 2009 You need to inititate session both in your captcha.php and this file using session_start Link to comment https://forums.phpfreaks.com/topic/155065-my-if-else-statement-not-working/#findComment-815591 Share on other sites More sharing options...
biblestamps Posted April 21, 2009 Author Share Posted April 21, 2009 Thank you- I had tried that before but was getting a header error. I recalled something about deleting all white spaces and I am not getting the error anymore. However now it is doing the opposite of what it was doing before... now it is simply sending even if I enter the incorrect validation code...? Link to comment https://forums.phpfreaks.com/topic/155065-my-if-else-statement-not-working/#findComment-815652 Share on other sites More sharing options...
biblestamps Posted April 21, 2009 Author Share Posted April 21, 2009 I have been doing some searching and I was able to get it working. NOW- the only thing is before when I would get the "go back and try again" error it would go back to the form with all fields filled in. Now it is going back to an empty form. I must have deleted something in the process of trying to get this working? Link to comment https://forums.phpfreaks.com/topic/155065-my-if-else-statement-not-working/#findComment-815686 Share on other sites More sharing options...
ricmetal Posted April 21, 2009 Share Posted April 21, 2009 yeah you have to set each post var in a session var and echo each session var in each fields value Link to comment https://forums.phpfreaks.com/topic/155065-my-if-else-statement-not-working/#findComment-815690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.