xstevey_bx Posted August 5, 2008 Share Posted August 5, 2008 Im creating a regitration form for my website and I have password encryption sorted and I can write simple inputs to the database. I am however having trouble with the DOB field. <select id="day" name="day" class="signupinput1"> <option value="-1">Day</option> <option value="1">1</option> </select> <select id="month" name="month" class="signupinput1"> <option value="-1">Month</option> <option value="1">January</option> </select> <select id="year" name="year" class="signupinput1"> <option value="2008">2008</option> </select> This is the html. What is the best way to construct a variable to write to the database. What data type is best e.g. Date, datetime, timestamp? Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/118325-solved-creating-dob-variable-to-be-written-to-mysql/ Share on other sites More sharing options...
akitchin Posted August 5, 2008 Share Posted August 5, 2008 since you don't need the time at all, the DATE type of field is your best bet. simply make sure you're padding all month and day values (i assume you'll construct a loop to populate those day/month select boxes) and then construct it according to: YYYY-MM-DD i would caution you on ensuring that you don't allow invalid day numbers for the various months (ie. 30 days has september, april, june and november; all others have 31, february has 28/29). you might be best off plugging/playing a calendar selection system from any one of the public scripts sites out there. Quote Link to comment https://forums.phpfreaks.com/topic/118325-solved-creating-dob-variable-to-be-written-to-mysql/#findComment-608949 Share on other sites More sharing options...
xstevey_bx Posted August 6, 2008 Author Share Posted August 6, 2008 $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; if ($year != 'none' || $month != 'none' || $day != 'none') { if ($year == 'none' || $month == 'none' || $day == 'none') { $errors[] = 'The birthdate you provided was not complete.'; } else { $dob = "$year"."$month"."$day"; } } if (empty($errors)) { $query = "INSERT INTO users (dob) VALUES('$dob')"; mysql_query($query) or die(mysql_error()); mysql_close(); } else { echo "$errors"; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/118325-solved-creating-dob-variable-to-be-written-to-mysql/#findComment-609658 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.