Skip to main content
Inspiring
August 3, 2007
Question

cfcalendar and mysql

  • August 3, 2007
  • 1 reply
  • 354 views
I am having a problem with getting data from a cfcalendar into MySQL. This control is not required and it is sometimes not even displayed depending on options the user selected earlier.

If the control does not display due to user selections, and when the action page is inserting data, it fails and gives the error that the data was truncated for the column.

If it does display and the user does not select a date it truncates the data also.

I have used <cfparam name="session.datechoice4" default=""> and it still does not work, if I do <cfparam name="session.datechoice4" default="0000-00-00"> it will work but I would like for it to just leave the db column set as NULL if a date is not selected.

Also, when using cfparam how do I get it to leave columns set as NULL when using default="". Using default="" sets the column as blank. I have tried default="(NULL)" but it did not seem to work with the about cfcalendar problem. TIA
    This topic has been closed for replies.

    1 reply

    Inspiring
    August 5, 2007
    try instead of using cfparam to set a default value for
    session.datechoice4 to use a cfif/cfelse login inside your actual sql
    statement checking for existence and validity of data. you then could do
    something like:
    <cfquery ....>
    INSERT INTO table (column)
    VALUES (
    <cfif len(trim(session.datechoice4)) gt 0 AND isValid("date",
    session.datechoice4)>
    <cfqueryparam value="#session.datechoice4#" cfsqltype="cf_sql_date">
    <cfelse>
    <cfqueryparam value="#session.datechoice4#" null="yes">
    </cfif>
    )
    </cfquery>

    of course, you can perform the data validation before the actual
    cfquery, and then use some set variable defining the validation state in
    the cfif/cfelse above

    hope this helps

    ---
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com