Jump to content

Recommended Posts

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

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.

$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();
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.