Jump to content

Enter birthdate into database from form


~kev~

Recommended Posts

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.

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/212366-enter-birthdate-into-database-from-form/
Share on other sites

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.

 

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']);

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.

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.