vikela Posted April 24, 2009 Share Posted April 24, 2009 i have the following code to collect a user date of birth and insert into mysql.i want to use the select menu for the date.what would be the best way of collecting the $_POST['data']. $Current = explode( "-", date( "n-j-Y" ) ); $Month = $Current[0]; $Day = $Current[1]; $Year = $Current[2]; $FirstYear = 1980; $LastYear = $Year; // Only display up to the current year - Change if you need // Output Days echo "<TR><TD>Day:</TD><TD><SELECT NAME='day'>\n"; for( $i = 1; $i <= 31; $i++ ) { echo "<OPTION VALUE='" . $i . "'"; if ( $i == $Day ) echo " SELECTED"; echo ">" . $i . "</OPTION>\n"; } echo "</SELECT></TD</TR>\n"; // Output Months echo "<TR><TD>Month:</TD><TD><SELECT NAME='month'>\n"; for( $i = 1; $i <= 12; $i++ ) { echo "<OPTION"; if ( $i == $Month ) echo " SELECTED"; echo ">" . date( "M", mktime( 0, 0, 0, $i, $Day, $Year ) ) . "</OPTION>\n"; } echo "</SELECT></TD</TR>\n"; // Output Years echo "<TR><TD>Year:</TD><TD><SELECT NAME='year'>\n"; for( $i = $FirstYear; $i <= $LastYear; $i++ ) { echo "<OPTION VALUE='" . $i . "'"; if ( $i == $Year ) echo " SELECTED"; echo ">" . $i . "</OPTION>\n"; } echo "</SELECT></TD</TR>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/155503-posting-date-of-birth-into-a-table/ Share on other sites More sharing options...
premiso Posted April 24, 2009 Share Posted April 24, 2009 I would setup the field to be a MySQL DATE field. Then on the submitted section do something like this (assuming that you used POST as the submit method) if (isset($_POST['submit'])) { $bday = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day']; // do the mysql insert with $bday as the field. } Before entering the date into the DB, you may want to run a checkdate on the values to make sure they are a valid date. Link to comment https://forums.phpfreaks.com/topic/155503-posting-date-of-birth-into-a-table/#findComment-818259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.