stelthius Posted March 5, 2009 Share Posted March 5, 2009 Hello everyone, Im in need of a little assistance with my menu for date of birth, basicly all 3 results need to be entered into one table in the database 'dob' but im unsure how to do that from the point im at right now, <?php echo '<select name="day" size="1">'; for ($x = 1; $x <= 31; $x++) { if ($form->value("day") == $x) $added = ' selected="selected"'; else $added = ''; echo "<option value='$x'$added>$x</option>"; } echo '</select>'; $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); echo '<select name="month" size="1">'; for ($x = 0; $x < sizeof($months); $x++) { if ($form->value("month") == $months[$x]) $added = ' selected="selected"'; else $added = ''; echo "<option value='$months[$x]'$added>$months[$x]</option>"; } echo '</select>'; $year = date("Y"); $firstYear = $year - 13; $finalYear = $year - 100; echo '<select name="year" size="1">'; for ($x = $firstYear; $x >= $finalYear; $x--) { if ($form->value("year") == $x) $added = ' selected="selected"'; else $added = ''; echo "<option value='$x'$added>$x</option>"; } echo '</select>'; ?> My general problem is getting it to input all 3 selected options in to 1 table in the database called dob as said above. any help is greatly appretiated. Link to comment https://forums.phpfreaks.com/topic/148158-help-with-php-select-menu/ Share on other sites More sharing options...
Stephen68 Posted March 5, 2009 Share Posted March 5, 2009 Can't you just put the 3 form field together and do a insert into the DB? Do you know how to make the connection to you database and run query's? <?php $month = mysql_real_escape_string($_POST['month']); $day = mysql_real_escape_string($_POST['day']); $year = mysql_real_escape_string($_POST['deadline_year']); $birthDate = $year."-".$month."-".$day; ?> Just include that into your query and run it, hope this helps. Link to comment https://forums.phpfreaks.com/topic/148158-help-with-php-select-menu/#findComment-777739 Share on other sites More sharing options...
stelthius Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks for your reply stephen but your miss understanding the question im not asking anything about connecting to the DB im asking is there anyways using php to get 3 drop down menu's to post into one table in the database, so in my situatiion i have menu 1 |day| menu 2 |month| menu 3 |year| now i want to put all 3 of the selected results into one table called dob, so im asking is there anyway to get day,month,year to go into dob or would i have to use a seperate table for each one, Link to comment https://forums.phpfreaks.com/topic/148158-help-with-php-select-menu/#findComment-777756 Share on other sites More sharing options...
Stephen68 Posted March 6, 2009 Share Posted March 6, 2009 The code I showed you puts it into one var and you just insert it into the MySql table. <?php //Put your DB Connection code and select DB code hree. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); $db_selected = mysql_select_db('dob', $link); //Now get the date and make it so that it will go into a MySql date field $month = mysql_real_escape_string($_POST['month']); $day = mysql_real_escape_string($_POST['day']); $year = mysql_real_escape_string($_POST['deadline_year']); $birthDate = $year."-".$month."-".$day; //Insert the date into the database $query = "INSERT INTO dob (dateField) VALUE ($dirthDate)"; $result = mysql_query($query); ?> Or something along those lines, I wrote that off the top of me head and code might not be 100% right. It should be good enough to show you what I was talking about though. Link to comment https://forums.phpfreaks.com/topic/148158-help-with-php-select-menu/#findComment-778221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.