Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old October 3rd, 2008, 10:26 AM
Member
 
Join Date: Mar 2007
Posts: 43
Default 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
Reply
  #2  
Old October 3rd, 2008, 03:17 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,963
Default

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.
Reply
  #3  
Old October 6th, 2008, 08:42 AM
Member
 
Join Date: Mar 2007
Posts: 43
Default

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
Reply
  #4  
Old October 6th, 2008, 08:51 AM
Member
 
Join Date: Mar 2007
Posts: 43
Default

Sorry - I meant acoder, not acer. Monday morning...
Reply
  #5  
Old October 6th, 2008, 11:14 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,963
Default

In your query, just add cfifs for the checking, e.g.
Expand|Select|Wrap|Line Numbers
  1. insert into tblWorkshops
  2. (<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
  3. values
  4. (<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)
Reply
  #6  
Old October 6th, 2008, 02:18 PM
Member
 
Join Date: Mar 2007
Posts: 43
Default

Quote:
Originally Posted by acoder
In your query, just add cfifs for the checking, e.g.
Expand|Select|Wrap|Line Numbers
  1. insert into tblWorkshops
  2. (<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
  3. values
  4. (<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)

Thats great, thanks for your help!

Neil
Reply
  #7  
Old October 6th, 2008, 02:27 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,963
Default

You're welcome :)
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.
Post your question now . . .
It's fast and it's free

Popular Articles