runnerjp Posted May 19, 2008 Share Posted May 19, 2008 ok i have my table set out like so <label for="birthmonth">Birth Month:</label> <select class="input" name="birthmonth" id="birthmonth"> <option value="January" <?php if($birthmonth == 'January') echo 'selected'; ?>>January</option> <option value="Febuary" <?php if($birthmonth == 'Febuary') echo 'selected'; ?>>Febuary</option> <option value="March" <?php if($birthmonth == 'March') echo 'selected'; ?>>March</option> <option value="April" <?php if($birthmonth == 'April') echo 'selected'; ?>>April</option> <option value="May" <?php if($birthmonth == 'May') echo 'selected'; ?>>May</option> <option value="June" <?php if($birthmonth == 'June') echo 'selected'; ?>>June</option> <option value="July" <?php if($birthmonth == 'July') echo 'selected'; ?>>July</option> <option value="August" <?php if($birthmonth == 'August') echo 'selected'; ?>>August</option> <option value="September" <?php if($birthmonth == 'September') echo 'selected'; ?>>September</option> <option value="October" <?php if($birthmonth == 'October') echo 'selected'; ?>>October</option> <option value="November" <?php if($birthmonth == 'November') echo 'selected'; ?>>November</option> <option value="December" <?php if($birthmonth == 'December') echo 'selected'; ?>>December</option> what should happen is the previous selected dob is echod but its not... culd it be that i join them all together like so $birthyear = mysql_real_escape_string( $_POST['birthyear']); $birthmonth = mysql_real_escape_string( $_POST['birthmonth']); $birthday = mysql_real_escape_string( $_POST['birthday']); $dob = $birthday.'-'.$birthmonth.'-'.$birthyear; ?? Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/ Share on other sites More sharing options...
BlueSkyIS Posted May 19, 2008 Share Posted May 19, 2008 echo $birthmonth and see what it looks like. Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544806 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 ok i selected December and it echo'd December as well as 19 been 19 and 1987 been 1987 Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544831 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 Hi the correct syntax is now selected = 'selected' not just 'selected'. try this and it should be ok. thanks Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544837 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 hey sadly this didnt do anything lol <option value="December" <?php if($birthmonth == 'December') echo ' selected="selected"'; ?>>December</option> Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544844 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 ok, try it outside of the select. for example <?php if($birthmonth == 'December'){ echo 'they chose december'; } ?> etc etc see what comes up, if this works then its something in your select. Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544853 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 yes that worked,,, what could it be?? Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544864 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 maybe is because youre missing the {} notice when you do it out of the select you are writing it as follows: if($birthmonth == 'December'){ echo 'they chose december'; } in the select you are missing these out. try adding them in Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544876 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 nope lolo <option value="December" <?php if($birthmonth == 'December') {echo ' selected="selected"';} ?>>December</option> Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544879 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 have you had a look at your source code for what it actually prints out. see if there is anything odd in there. it may give you a clue. Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544880 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 im thinking that maybe its because its stored as $dob = $birthday.'-'.$birthmonth.'-'.$birthyear; would i have to break it down again or something? Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544882 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 you are asking about the $birthmonth in the month select arent you? and you are saying if $birthmonth == something then so you dont need to worry about $dob because you are querying $birthmonth. am i right or am i missing something? what does your source code say? Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544885 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 but what im doing is i want to pull for the db what the user selected the last time they where inserting there dob... for example my gender is <select class="input" id="gender" name="gender"> <option value="Male" <?php if($gender == 'Male') echo 'selected'; ?>>Male</option> <option value="Female" <?php if($gender == 'Female') echo 'selected'; ?>>Female</option> </select> so if i selected male it will show male in the table..and does but i add the gender into the database... so i can pull out gender... but when i insert dob into the db i use $dob = $birthday.'-'.$birthmonth.'-'.$birthyear; so in my db i just have $dob so i can only echo $dob from my table yes.... Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544891 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 right if $dob is whatever you pulled out of the database, the you need to seperate it into $day $month and $year. but i assumed you already did that since you were saying if $birthmonth == something etc etc $birthmonth needs to be only the month part of whatever you pulled from the db for it to work. if youre saying the following: if ($birthmonth == "december"){ } Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544897 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 sorry didnt finish my post if youre saying if ($birthmonth == "december"){ show this; } and $birthmonth actually equals $birthday.'-'.$birthmonth.'-'.$birthyear then it will never work. hope that helps Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544899 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 can i serparte it back again then?? Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544917 Share on other sites More sharing options...
Pickle Posted May 19, 2008 Share Posted May 19, 2008 yeah just use explode to seperate them http://uk.php.net/manual/en/function.explode.php Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544920 Share on other sites More sharing options...
runnerjp Posted May 19, 2008 Author Share Posted May 19, 2008 sooo print_r(explode('|', $$dob, 3)); Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-544949 Share on other sites More sharing options...
Pickle Posted May 20, 2008 Share Posted May 20, 2008 yeah, you dont really need the 3. and you would then have an array of 3 elements. $date_array = explode('|', $$dob); and then you can print each seperate element like echo $date_array[0]; etc Link to comment https://forums.phpfreaks.com/topic/106305-not-echoing-out-selected-dob/#findComment-545490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.