4 Replies Latest reply on Sep 4, 2008 9:22 AM by pja5362

    cfqueryparam insert error

      I'm trying to update an INSERT query statement with <cfqueryparam>s and am getting an error.

      It worked fine before, and when I only ad the cfqp to the "WHERE" statement, but when I mix cfqp into even one "SET" item, it throws an error.

      What am I doing wrong??

        • 1. Re: cfqueryparam insert error
          paross1 Level 2
          For starters, stop enclosing your CFQUERYPARAM tags within single quotes.

          '<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#" />' is not necessary...

          use <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#">

          • 2. Re: cfqueryparam insert error
            pja5362 Level 1
            Fantastic! That did the trick! Thanks!!

            I retained all instances of wrapping string-based query variables in single quotes when i updated the site with cfqp's, and am only getting errors when trying to write to the database. should i get rid of them all, even in simple "SELECT" queries?

            Also, should i add the null parameter to all the items in my queries that write to the db? For example:

            <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#" null="#YesNoFormat(Len(Trim(Form.FirstName)))#">

            I came across the null variable for the first time this morning and don't know anything about it.
            • 3. Re: cfqueryparam insert error
              Dan Bracuk Level 5
              If Cold Fusion gives you an empty string, and the datatype is text, you can make the field null or an empty string. Your choice.

              If it's numeric or date, you have to make it null or you'll have a data type mismatch.

              The way I do it is to set some variable to either true or false before the query, and set the cfqueryparam null attribute to that variable.
              • 4. Re: cfqueryparam insert error
                pja5362 Level 1
                Gotcha. Thanks to you both for the quick replies.