I am going to have three combo boxes (DD-MM-YYYY) to obtain the date of birth of a user who is going to register in my site. My problem is how should i store this in mysql database?
try Insert into table_name (DD,MM,YY) values (12,03,1985) OR $dd='12'; $mm='03'; $yy='1986'; echo $DB=$dd.$mm.$yy; //now save the $DB PHP:
Ideally you should create ONE field (datatype=date) in your database to store date of birth. How you present this field on the form is up to you. Some website provide javascript popup calendar when they expect the user to enter a date. However, usually this is not the case with date of birth. If you are providing three list boxes, there are a couple of gotchas. E.g. user could specify a date in the future. To prevent this (and to disallow registrations for people below 13 years) truncate the year combo to 1998. Checking dates is tricky since not all months have 31 days. Then there are leap years. I'd recommend that you use the PHP checkdate() function to validate date: <?php $mm = (int) $_POST["dob_mm"]; $dd = (int) $_POST["dob_dd"]; $yy = (int) $_POST["dob_yy"]; if (checkdate($mm, $dd, $yy)){ $dob = "$yy-$mm-$dd"; // <- this is the format mysql expects for dates $query = "INSERT INTO whatever (x, y, z, dob) values ('x', 'y', 'z', '$dob')"; } else { // reject user input } ?> PHP: