Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2002
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating table - problem with blank fields (ColdFusion)

    am updating a table using a standard insert statement with information from a form. However if a field is blank in the form it is inserting a default value - either 01/01/00 for date or 0 for int. What I want is that if the field is blank then nothing gets updated. There are no default values set in the database.

    This is my insert code

    <cfquery name="updateBasics" datasource="db">
    update tblThesis set
    thesisEX13Recd = '#form.frm_ex13#',
    thesisExamPanelAppointed = '#form.frm_panel#',
    thesisVivaDate = '#form.frm_viva#',
    ExamResultID = '#form.frm_result#'
    where thesisID = #session.thesis.thesisID#
    </cfquery>

    I've tried the following but I get an error (I'm hoping I don't have to do it like this and put in an if clause for every field!).

    <cfquery name="updateBasics" datasource="db">
    update tblThesis set
    thesisEX13Recd = '#form.frm_ex13#',
    thesisExamPanelAppointed = '#form.frm_panel#',
    <cfif #form.frm_viva# is not "">
    thesisVivaDate = '#form.frm_viva#',
    </cfif>
    ExamResultID = '#form.frm_result#'
    where thesisID = #session.thesis.thesisID#
    </cfquery>

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    UK
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What error are you doing?

    You could always do:

    <cfparam name="variablename" default="0">

    And if it's not already set then it will be defaulted to 0. Do this before the query


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •