~kev~ Posted September 2, 2010 Share Posted September 2, 2010 How can I build a form with a drop down menu with the year, day, month? And then send that information to a database. If there is another/better option besides a drop down menu? If so, please tell me. The rest of the form is working fine, and all the inforamtion is going to the database - last name, first name, address, phone number, zip code, race,,,,,,,,,. I work for a not-for-profit medical office - we provide medical services to the local people who can not afford to go to a regular doctor. We need a simple way to keep track of patient information. One of the things we need to enter is the birthdate. Searching the forums provided a lot of results, but the words date and form are used so much, I can not find anything that helped me. I also looked through php.net, but can not find anything there. Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted September 2, 2010 Share Posted September 2, 2010 if you do the form like this nice and fast $display .= '<select name="DateOfBirth_Day"> <option value="" >- Day -</option>'; for ($i = 1; $i <= 31; $i++) { if ($_POST['DateOfBirth_Day'] == $i){ $display .= '<option value="'.$i.'" selected>'.$i.'</option>'; } else{ $display .= '<option value="'.$i.'" >'.$i.'</option>'; } } $display .='</select> / M <select name="DateOfBirth_Month"> <option value="" >- Month -</option>'; for ($i = 1; $i <= 12; $i++) { if ($_POST['DateOfBirth_Month'] == $i){ $display .= '<option value="'.$i.'" selected>'.GetMonthString($i).'</option>'; } else{ $display .= '<option value="'.$i.'" >'.GetMonthString($i).'</option>'; } } $display .= '</select> <select name="DateOfBirth_Year"> <option value="" >- Year -</option>'; $thisyear = date('Y'); $now = $thisyear - 6; $end = $thisyear - 100 ; for ($now; $now >= $end; $now--) { if ($_POST['DateOfBirth_Year'] == $now){ $display .= '<option value="'.$now.'" selected>'.$now.'</option>'; } else{ $display .= '<option value="'.$now.'" >'.$now.'</option>'; } } $display .= '</select> '; echo $display ; Now you need to deal with the post etc $ageTime = mktime(0, 0, 0, $_POST['DateOfBirth_Day'], $_POST['DateOfBirth_Month'], $_POST['DateOfBirth_Year']); I like Unix timestamp but there are many ways you can do it. Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted September 2, 2010 Share Posted September 2, 2010 Sorry I used a function there which i did not include function GetMonthString($n){ $timestamp = mktime(0, 0, 0, $n, 1, 2010); return date("F", $timestamp); } Quote Link to comment Share on other sites More sharing options...
~kev~ Posted September 2, 2010 Author Share Posted September 2, 2010 Now you need to deal with the post etc $ageTime = mktime(0, 0, 0, $_POST['DateOfBirth_Day'], $_POST['DateOfBirth_Month'], $_POST['DateOfBirth_Year']); I like Unix timestamp but there are many ways you can do it. Thank you very much for your help. I took the code you posted, and put it into a form Select Birthday: <form name="formBirthdate"> the code you posted </form> I hope that was right. For the post I have been using this $varLastname = $_POST['formLastname']; PrepSQL($varLastname) . ", " . I'am not sure how to use the second piece of code you posted. Where is it supposed to go? $ageTime = mktime(0, 0, 0, $_POST['DateOfBirth_Day'], $_POST['DateOfBirth_Month'], $_POST['DateOfBirth_Year']); Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted September 2, 2010 Share Posted September 2, 2010 That is the code when the user submits the data back to the server as in when they fill out the form and select from the drop down menus. That part of the code will work out they they selected and make it into a Unix timestamp. Check out http://php.net/manual/en/function.mktime.php You save that time stamp to MYSQL fine and then when your looking to display it check out http://www.php.net/manual/en/function.date.php to get into readable format. Quote Link to comment Share on other sites More sharing options...
~kev~ Posted September 2, 2010 Author Share Posted September 2, 2010 Thank you again, but that php.net midas well be in greek or latin. Because its way over my head. There are a lot of example there, but I have not found anything that I can use. You said that I was going to have to deal with the post, so I took this code and added it to the post statement. $ageTime = mktime(0, 0, 0, $_POST['DateOfBirth_Day'], $_POST['DateOfBirth_Month'], $_POST['DateOfBirth_Year']); $varBirthdate = $_POST['$ageTime = mktime(0, 0, 0, $_POST['DateOfBirth_Day'], $_POST['DateOfBirth_Month'], $_POST['DateOfBirth_Year']']; And now I'am getting a syntax error, unexpected T_STRING, expecting ']' in /**path-removed**/myform1.php on line 41 Regardless if I have the closing '] or not, I get different errors 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.