collin84 Posted April 15, 2006 Share Posted April 15, 2006 HiI'm new to php and have just started using it for an assignment at universityI'm wanting to create a date input section on a website using 3 combo boxes for day, month and yearI then want to store this date in a mysql table$month = array(1=>"January", "February", "March"........);$day = $_POST['day'];$year = $_POST['year'];$query = "INSERT INTO table (date) VALUES ('$year-???-$day')";The only question i have got is how to get the numerical value of the selected month and put it in place of "???" ?ThanksCol Quote Link to comment Share on other sites More sharing options...
Barand Posted April 15, 2006 Share Posted April 15, 2006 Display month names in the combo but use month numbers for the values[code]<?phpif (isset ($_POST['submit'])) { $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $date = "$year-$month-$day"; $query = "INSERT INTO table (date) VALUES ('$date')"; echo $query;}?><FORM method='POST'>Day<SELECT name='day'> <?php for ($d=1; $d <= 31; $d++) { printf ("<OPTION value='%1\$02d'>%1\$d</OPTION>", $d); } ?></SELECT>Month<SELECT name='month'> <?php for ($m=1; $m <= 12; $m++) { $mname = date('F', mktime(0,0,0,$m,1,2006)); printf ("<OPTION value='%02d'>%s</OPTION>", $m, $mname); } ?></SELECT>Year<SELECT name='year'> <?php for ($y=2001; $y <= 2006; $y++) { echo "<OPTION value='$y'>$y</OPTION>\n"; } ?></SELECT><INPUT TYPE='SUBMIT' name='submit' value='Submit'></FORM>[/code] Quote Link to comment Share on other sites More sharing options...
collin84 Posted April 17, 2006 Author Share Posted April 17, 2006 Thanks for the help, its working fine now. Thought it must have been something simple but couldn't figure it out and was spending far too long trying.Col Quote Link to comment 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.