Re: NULL Date Entries...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1 July 2010 23:40, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Thu, 2010-07-01 at 14:26 -0700, Don Wieland wrote:
>
>> In one of my forms, I am building a variable that I can use as an
>> INSERT string.
>>
>> On my form, I have several DATE fields which exist of 3 fields MM - DD
>> - YYYY
>>
>> when I build my string it looks like this:
>>
>> array('dbf'=>'applicant_dob',
>> 'f'=>array('applicant_dob_1','applicant_dob_2','applicant_dob_3'),
>> 'req'=>0, 's'=>'/'),
>>
>> This enters in the DB fine when there is a DATE, but when these fields
>> are left empty, it inserts into the the DB as 2069-12-31.
>>
>> How does one deal with this?
>>
>> Don Wieland
>>
>
>
> How are you allowing the user to select a date? If it is three form
> fields, it might be logical to use select lists with the allowed range
> of values in.
>
> If that's not possible, use lines like this to set default values:
>
> $month = (isset($_POST['month']) && preg_match('/^\d{2}$/',
> $_POST['month']))?$_POST['month']:'01';
>
> which would set a default month value of '01' if there was either no
> month value sent or it wasn't a 2-digit value.
>

Not sure I'd bother with a preg there, intval should do it nicely.
Keep in mind you probably want to check the date at the end of this
with http://dk2.php.net/manual/en/function.checkdate.php or something
similar.

Regards
Peter

-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux