xXREDXIIIXx Posted May 7, 2009 Share Posted May 7, 2009 OK its my first day here, I usually like to figure these problems out by myself but i been looking at the same code for a while now all I see are colours . This is the code that is not working, no matter what input i give it, it always returns as the last result due to it saying everything is the default 'selected' this is from registration.php $genders = array('Select Gender', 'Male', 'Female'); echo '<select name="gender" class="text_form_field">'; foreach($genders as $gender){ echo '<option value="'.$gender.'"'.($_SESSION['gender'] == $gender ? ' selected="selected"':'').'>'.$gender.'</option>';} echo '</select>'; echo $_SESSION['gender_check']; unset($_SESSION['gender_check']); ?> Here is the php_registration.php code $gender = $_POST['gender']; $_SESSION['gender'] = $gender; if ($gender == 'Select Gender'){ $_SESSION['gender_check'] = "<br><span class=\"text_error\">Gender is required.</span>";} If anyone can see my typo or sommit plz tell me I can only learn from my mistakes Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 What do you mean it always return the last result? What's the last result? Female? Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829034 Share on other sites More sharing options...
xXREDXIIIXx Posted May 7, 2009 Author Share Posted May 7, 2009 yes last result is Female the output HTML looks like this: <tr> <td align="right" valign="top" width="30%">Gender:</td> <td> <select name="gender" class="text_form_field"> <option value="Select Gender" selected="selected">Select Gender</option> <option value="Male" selected="selected">Male</option> <option value="Female" selected="selected">Female</option> </select><br> <span class="text_error">Gender is required.</span> </td> </tr> Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829037 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Can you put this in and tell me what it outputs: $genders = array('Select Gender', 'Male', 'Female'); var_dump($_SESSION['gender']); // added this line echo '<select name="gender" class="text_form_field">'; foreach($genders as $gender){ echo '<option value="'.$gender.'"'.($_SESSION['gender'] == $gender ? ' selected="selected"':'').'>'.$gender.'</option>';} echo '</select>'; echo $_SESSION['gender_check']; unset($_SESSION['gender_check']); ?> But try using 3 equals instead of 2 before you do that. Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829040 Share on other sites More sharing options...
xXREDXIIIXx Posted May 7, 2009 Author Share Posted May 7, 2009 added line prints: string(4) "Male" 3x = nothing. Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829044 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Hmm... it should work. Try clearing your cache, etc. Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829049 Share on other sites More sharing options...
xXREDXIIIXx Posted May 7, 2009 Author Share Posted May 7, 2009 Hmm... it should work. Try clearing your cache, etc. cleared it no change: can u check form your end? http://www.clansngamers.com/register.php errors appear on gender / location but not languages dispite the code being the same :S Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829053 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 I didn't get any errors on Gender and that was the only thing I did fill in. But I do get the Female even though I selected Male and I do confirm that the source has everything selected. In the foreach loop, can you add this: echo $_SESSION['gender'] . ' & ' . $gender . ' = ' . ($_SESSION['gender'] == $gender); Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829055 Share on other sites More sharing options...
xXREDXIIIXx Posted May 8, 2009 Author Share Posted May 8, 2009 I didn't get any errors on Gender and that was the only thing I did fill in. But I do get the Female even though I selected Male and I do confirm that the source has everything selected. In the foreach loop, can you add this: echo $_SESSION['gender'] . ' & ' . $gender . ' = ' . ($_SESSION['gender'] == $gender); foreach($genders as $gender){ echo '<option value="'.$gender.'"'.($_SESSION['gender'] == $gender ? ' selected="selected"':'').'>'.$gender.'</option>'; echo $_SESSION['gender'] . ' & ' . $gender . ' = ' . ($_SESSION['gender'] == $gender);} if you ment like that its added and online; no change here is the language code that works: <?php // LOCATION $locations = array('Select Location', 'United Kingdom', 'United States', 'Region 3'); echo '<select name="location" class="text_form_field">'; foreach($locations as $location){ echo '<option value="'.$location.'"'.($_SESSION['location'] == $location ? ' selected="selected"':'').'>'.$location.'</option>';} echo '</select>'; echo $_SESSION['location_check']; unset($_SESSION['location_check']); ?> Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829063 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Is it live? I don't see the display anywhere. Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829066 Share on other sites More sharing options...
xXREDXIIIXx Posted May 8, 2009 Author Share Posted May 8, 2009 Is it live? I don't see the display anywhere. <?php // GENDER $genders = array('Select Gender', 'Male', 'Female'); echo '<select name="gender" class="text_form_field">'; foreach($genders as $gender){ echo '<option value="'.$gender.'"'.($_SESSION['gender'] == $gender ? ' selected="selected"':'').'>'.$gender.'</option>'; echo $_SESSION['gender'] . ' & ' . $gender . ' = ' . ($_SESSION['gender'] == $gender);} echo '</select>'; echo $_SESSION['gender_check']; unset($_SESSION['gender_check']); ?> ALL Live :-\ Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829071 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 I see it. Apparently $_SESSION['gender'] is either '' or NULL. I don't know which. Can you put var_dump($_SESSION['gender']) in the foreach instead so we can see which it is. Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829083 Share on other sites More sharing options...
xXREDXIIIXx Posted May 8, 2009 Author Share Posted May 8, 2009 I see it. Apparently $_SESSION['gender'] is either '' or NULL. I don't know which. Can you put var_dump($_SESSION['gender']) in the foreach instead so we can see which it is. Live, starts as NULL obviously then changes to what ever ya selected. Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829086 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Did you take down gender? Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829098 Share on other sites More sharing options...
xXREDXIIIXx Posted May 8, 2009 Author Share Posted May 8, 2009 Did you take down gender? yeah I was getting a internal error when that was up(when form was submitted completely empty), so I took that off I hav copyed all the code onto another page called reg.php I changed something on the month section of birthday and now it seems to be working (I have stripped all of the errors from the personal section - wanted to localize the error). I am going to add the error codes on and see what happens will report back tonight. Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829103 Share on other sites More sharing options...
xXREDXIIIXx Posted May 8, 2009 Author Share Posted May 8, 2009 OK Reporting back, All I done was shortened the variable names, So this: <?php // GENDER $genders = array('Select Gender', 'Male', 'Female'); echo '<select name="gender" class="text_form_field">'; foreach($genders as $gender){ echo '<option value="'.$gender.'"'.($_SESSION['gender'] == $gender ? ' selected="selected"':'').'>'.$gender.'</option>'; echo $_SESSION['gender'] . ' & ' . $gender . ' = ' . ($_SESSION['gender'] == $gender);} echo '</select>'; echo $_SESSION['gender_check']; unset($_SESSION['gender_check']); ?> Now looks like this: <?php // GENDER $gs = array('Select Gender', 'Male', 'Female'); echo '<select name="gender" class="text_form_field">'; foreach($gs as $g){ echo '<option value="'.$g.'"'.($_SESSION['gender'] == $g ? ' selected="selected"':'').'>'.$g.'</option>'; echo $_SESSION['gender'] . ' & ' . $gender . ' = ' . ($_SESSION['gender'] == $gender);} echo '</select>'; echo $_SESSION['gender_check']; unset($_SESSION['gender_check']); ?> That was it, Most sillest thing I have come accross to date (and yes I check there was no variable clashes) Think this can be classed as solved? Link to comment https://forums.phpfreaks.com/topic/157291-form-session-dropdown-menu/#findComment-829111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.