 | 
October 3rd, 2008, 10:26 AM
| | Member | | Join Date: Mar 2007
Posts: 43
| | insert blank / null date field into database using coldfusion
Hi,
How do I insert a null or blank field into a database using coldfusion? I'm new to CF and its proviing a bit tricky!
My database date field accepts null values (I think - theres no default value or validation rule).
The input box on the form is this:
<input type="text" name="QuotePDate" maxlength="10" size="12" />
and is handled by the action form as this:
insert into tblWorkshops
(QuotePDate etc..)
values
(#form.QuotePDate#, etc
How can I get the database to accept the null value? The users of the form won't need to always enter a date, tho they may need to update it later on.
Thanks!
Neil
| 
October 3rd, 2008, 03:17 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,963
| |
Why not have null as the default in the database and not insert anything for the date value if it's not input. To do this, just check the value input by the user. If it's empty, don't add to the list of fields to insert.
| 
October 6th, 2008, 08:42 AM
| | Member | | Join Date: Mar 2007
Posts: 43
| | Quote: |
Originally Posted by acoder Why not have null as the default in the database and not insert anything for the date value if it's not input. To do this, just check the value input by the user. If it's empty, don't add to the list of fields to insert. | Thanks acer - but how exactly do I do this?
Neil
| 
October 6th, 2008, 08:51 AM
| | Member | | Join Date: Mar 2007
Posts: 43
| |
Sorry - I meant acoder, not acer. Monday morning...
| 
October 6th, 2008, 11:14 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,963
| |
In your query, just add cfifs for the checking, e.g. - insert into tblWorkshops
-
(<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
-
values
-
(<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)
| 
October 6th, 2008, 02:18 PM
| | Member | | Join Date: Mar 2007
Posts: 43
| | Quote: |
Originally Posted by acoder In your query, just add cfifs for the checking, e.g. - insert into tblWorkshops
-
(<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
-
values
-
(<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)
|
Thats great, thanks for your help!
Neil
| 
October 6th, 2008, 02:27 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,963
| |
You're welcome :)
|  | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 204,687 network members.
|