Re: NULL Date Entries...
| From: | Ashley Sheridan | Date: | Thu, 01 Jul 2010 21:40:06 +0000 |
| Subject: | Re: NULL Date Entries... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-306617@lists.php.net to get a copy of this message | ||
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.
Thanks,
Ash
http://www.ashleysheridan.co.uk