dsaba Posted March 20, 2007 Share Posted March 20, 2007 this is driving me nuts, i've been at it for hours basically the rundown of what i'm trying to do is this: 1. i generate a random code and store that code in a session 2. i have an html form that asks for that code 3. there is an if/else statement that display success statements if you type in the correct code or if you didn't type in the correct code here is the code (the parent brackets are the ones that are farthest out, its better if you paste this code into a php editor to see the if/else statement more clearly)(sorry thats how I tab if/else statements) <?php session_start(); ///////////////////////////////////////////////////// srand((double)microtime()*1000000); $randomnumber = md5(rand(0,9999)); $code = substr($randomnumber, 17, 5); $_SESSION['code'] = $code; ////////////////////////////////////////////////////// $field = $_POST['field']; $field_func = "hello"; ///////////////////////////////////////////////////////////////////////////////////////// if ($field != "") { if ($field == $_SESSION['code']) { if ($field_func == "hello") { echo "function = true"; echo '<br>'; echo "Entered: "; echo $field; echo '<br>'; echo "Session was: "; echo $_SESSION['code']; } else { echo "function = false"; echo '<br>'; echo "Entered: "; echo $field; echo '<br>'; echo "Session was: "; echo $_SESSION['code']; } } elseif ($field != $_SESSION['code']) { echo "field does not equal the session"; } } else { echo "Type in this code: "; echo $_SESSION['code']; echo '<br>'; echo '<form name="whatever" method="POST" action="new.php"><input name="field" type="text" class="form-field" size="30" maxlength="15" /><input type="submit" name="Submit" value="Submit" /></form>'; } ?> *EDIT- this code viewer in this forum fucks up my tabs so i took a picture http://img338.imageshack.us/img338/8283/samplecodeih6.png ############THE PROBLEM########## No matter if you type the correct code in it always shows "field does not equal the session" this is apparently not true!, please help - thanks Link to comment https://forums.phpfreaks.com/topic/43550-solved-why-doesnt-this-work-formsessionifelse-statementwell-explainedeasycod/ Share on other sites More sharing options...
SammyGunnz Posted March 20, 2007 Share Posted March 20, 2007 First question (Which may or not have any effect) before I look at the rest...where is $field defined? Because unless you do: <?php $field = $_POST['field']; ?> ...You're asuming that register_globals is enabled wherever the script is running. Link to comment https://forums.phpfreaks.com/topic/43550-solved-why-doesnt-this-work-formsessionifelse-statementwell-explainedeasycod/#findComment-211494 Share on other sites More sharing options...
dsaba Posted March 20, 2007 Author Share Posted March 20, 2007 field is defined in the code i posted -the one that actually contains TEXT the picture is just of the if/else statement, so look at the scrollbar code to see everything Link to comment https://forums.phpfreaks.com/topic/43550-solved-why-doesnt-this-work-formsessionifelse-statementwell-explainedeasycod/#findComment-211497 Share on other sites More sharing options...
SammyGunnz Posted March 20, 2007 Share Posted March 20, 2007 Never mind. I see that the above reference. However, the code looks kinda cluttered and you have echo's everywhere for me to put forth any effort to look through it. Good luck :-P Link to comment https://forums.phpfreaks.com/topic/43550-solved-why-doesnt-this-work-formsessionifelse-statementwell-explainedeasycod/#findComment-211499 Share on other sites More sharing options...
dsaba Posted March 20, 2007 Author Share Posted March 20, 2007 i figured it out, when I send the form information to the page it reloads it and hence erases the past session and makes a new one, so the code does not match Link to comment https://forums.phpfreaks.com/topic/43550-solved-why-doesnt-this-work-formsessionifelse-statementwell-explainedeasycod/#findComment-211554 Share on other sites More sharing options...
dsaba Posted March 20, 2007 Author Share Posted March 20, 2007 thanks for the help dsaba! you da man! Link to comment https://forums.phpfreaks.com/topic/43550-solved-why-doesnt-this-work-formsessionifelse-statementwell-explainedeasycod/#findComment-211565 Share on other sites More sharing options...
dsaba Posted March 20, 2007 Author Share Posted March 20, 2007 no problem Link to comment https://forums.phpfreaks.com/topic/43550-solved-why-doesnt-this-work-formsessionifelse-statementwell-explainedeasycod/#findComment-211566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.