Jump to content
Larry Ullman's Book Forums

Insert Date Of Birth Into Database Using Select Lists

Recommended Posts

hi...All :o


I need to add a user registration form to my web site and have intended to obtain user's date of birth through the form. I used 3 combo boxes to select to users their date of birth. so i need to validate these values before submitting and need to insert these values to the database.





<form action=""  method="post">
 <label>Date of Birth : </label>

// month array 

$month = array( 1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August');

	echo  '<select name="' . $month . '">';	

	foreach ( $month as $k => $v ) {

		echo '<option name="'. $v . '"  value="' . $k . '">' . $v . '</option><br />';

	echo '</select> <select name="day">';

	for ( $i = 1; $i <= 31; $i++) {

                    echo '<option name="'. $i . '"  value="' . $i . '">' . $i . '</option><br />';


	echo '</select> <select name="year">';

	for ( $i = 1950; $i <= 2050; $i++) {
		echo '<option name="'. $i . '"  value="' . $i . '">' . $i . '</option><br />';


	echo '</select>';


<br /><br />

<input type="submit"  value="Submit"  name="submit" />

<input type="hidden"   value="TRUE"  name="submitted" /></form>



My database name is : mydb

My table is : users

Table column is : dob DATE


I need php coding for validation and insert into database.




Thanks again and look forward to hearing from you soon.


Tharanga Nuwan

Link to comment
Share on other sites

No offence but in my opinion this forum should be used by people who are learning PHP - people who have tried, got stuck and need guidance. It doesn't look like you've even attempted to write the code for yourself - and I'm not (and I doubt anyone else is) about to do it for you.


At least try to write the code first and if you get stuck then come back for help.

  • Upvote 2
Link to comment
Share on other sites

I'm with Stuart on this one.


I don't remember the exact chapter, but toward the beginning of the book, Larry has a chapter about handling dates from drop-down lists, which seems to be exactly what you are looking for.


Please check that out first.

  • Upvote 1
Link to comment
Share on other sites


  • Create New...