Forums

This topic is locked

date of birth

Posted 19 Jan 2008 23:27:17
1
has voted
19 Jan 2008 23:27:17 Dave K posted:
Hi guys please have patience with me as im a noob to mysql & asp

I`m trying to setup a form to record a date of birth and have created 3 dropdown menus to retreve the day, month, year.

how would i go about translating the 3 field values into a format that keeps mysql happy?

this has been really frustrating and i have looked all over for a solution in noob terms.

cheers guys

ok i have made a breakthrough but still having problems.

<pre id=code><font face=courier size=2 id=code> &lt;input name="dt" type="hidden" id="dt" value="&lt;%Response.Write Year(Request.Form("dobYearField") & "-" & Month(Request.Form("dobMonthField") & "-" & Day(Request.Form("dobDayField")%&gt;"&gt;</font id=code></pre id=code> i have used this hidden field to get the 3 values and it enters the date with no errors, BUT when i check the database it always reads " 1899-12-30 " no matter what i input into the input fields <img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>

Any ideas?

Edited by - hellfreezes on 20 Jan 2008 00:54:43

Replies

Replied 21 Jan 2008 00:03:44
21 Jan 2008 00:03:44 Javier Castro replied:
hey Dave,

so have the form: the 3 drop down menus with your numbers. Once you select your correct numbers you send the form to your db with the POST action, right?

or do you send it to another page, where you add your hidden field and then you send it to your db.

Not clear, but I would suggest to test if the values you are passing to the db are good.

I did not understand all but I hope it helps. I just tried it in my computer and all prints fine. But it would be good to see a copy of your code.

Javier



Replied 21 Jan 2008 22:17:15
21 Jan 2008 22:17:15 Alan C replied:
Hi
I was reading your post earlier today, then while looking for a function in some work I did ages ago I found this . . .

<pre id=code><font face=courier size=2 id=code>
function assemble_date($dd, $mm, $yyyy)
{
# takes the three parts of the date from the form input and returns an iso formatted date
# ready for mysql to insert into the table
# cleanup consists of removing anything except numbers and limiting length
# padding zeros are added when necessary
# final format will be YYYYMMDD
#
# Copyright Alan C____ May 2006
$regex = '[^0-9]'; // means anything except digits 0 thru 9
$yyyy = preg_replace($regex,'',$yyyy);
if(strlen($yyyy)&lt;4) {$yyyy = '0000';} // something wrong, less than 4 digits entered for year
$mm = preg_replace($regex,'',$mm);
$mm = str_pad($mm, 2, '0', STR_PAD_LEFT);
$dd = preg_replace($regex,'',$dd);
$dd = str_pad($dd, 2, '0', STR_PAD_LEFT);
return $yyyy.$mm.$dd;
}

</font id=code></pre id=code>

I have to say that I prefer textboxes to dropdown menus for dates, but each to his own preference, you can adapt this to take your input, as written it does not test whether or not the individual parts of the date are within their appropriate ranges, I think I did that elsewhere - have fun <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Reply to this topic