r00ttap Posted March 6, 2009 Share Posted March 6, 2009 Maybe I've been starring at code too long but is there any reason why this wouldn't work? I have a menu for the Year, Month, and Day and none seem to be working but I'll post the year as an example. <select name="year"> <option selected value="<?php echo date(Y); ?>"><?php echo date(Y); ?></option> <option value="2009">2009</option> <option value="2010">2010</option> </select> It works as much as the current year being displayed by default but if I submit the form without touching the drop down menu it won't send the year to the database but if I manually select the year it will work. What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/148298-value-selected-date/ Share on other sites More sharing options...
pcw Posted March 6, 2009 Share Posted March 6, 2009 <?php print "<select name=\"year\">"; print "<option value=\"<?php echo 'date(Y)' echo 'selected';?><?php echo date(Y);?></option>"; print "<option value=\"2009\">2009</option>"; print "<option value=\"2010\">2010</option>"; print "</select>"; ?> Thats should do it Quote Link to comment https://forums.phpfreaks.com/topic/148298-value-selected-date/#findComment-778581 Share on other sites More sharing options...
phant0m Posted March 6, 2009 Share Posted March 6, 2009 I think it should be like this: <option selected="selected" value="<?php echo date(Y); ?>"><?php echo date(Y); ?></option> Quote Link to comment https://forums.phpfreaks.com/topic/148298-value-selected-date/#findComment-778617 Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Nothing jumps out at me. Only issue I can think of (and never tried it so no idea if it would cause an issue) is that you have a duplicate value (ie, you have used todays year and listed 2009 as well). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148298-value-selected-date/#findComment-778644 Share on other sites More sharing options...
Maq Posted March 7, 2009 Share Posted March 7, 2009 Must be the way you're using POST. We would need to see the processing part. I used this code and it outputs "2009" to the browser when I don't select anything... if(isset($_POST['submit'])) { echo $_POST['year']; } ?> </pre> <form action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>" method="POST"> ; ; 2009; 2010; < Oh, and why do you have date(Y) and 2009? Quote Link to comment https://forums.phpfreaks.com/topic/148298-value-selected-date/#findComment-778653 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.