Form Action page error

I'm having a problem with a form submission. I'm currently using conditional logic in an "action page" to update or insert a form. When I hit submit I get an error message stating " The CREATIONDATE fieldname cannot be found in the leads table."

The problem is that I'm not updating the "CreationDate" input into the the Leads table (see attached code). It's my understanding that using cfupdate and formfields that what you put under the formfields variables is what gets updated or inserted. I do have a input tag with the name of CreationDate in the form, but again it is not in the code to be inserted so why is Coldfusion trying to update the field?

Any help would be greatly appreciated :)
<<<<<<<<<<<<<<PAGE FORM SENDS TO>>>>>>>>>>>>>>>>>

<!--- Insert or update? --->
<cfset EditMode=IsDefined("FORM.LeadID")>

<cfif EditMode>
 <!--- Update Lead --->
 <cfupdate datasource="#application.datasource#"
          tablename="leads"
          formfields="FirstName,
          				LastName,
                        Secondary_first,
                        Secondary_last,
                        Company,
                        HomePhone,
                        WorkPhone,
                        MobilePhone,
                        OtherPhone,
                        OtherPhoneLabel,
                        AltPhone,
                        AltPhoneLabel,
                        EmailAddress,
                        SecondEmail,
                        Website,
                        PropertyAddress,
                        City,
                        State,
                        ZipCode">
 <cfset action="UPDATED">
   <cflocation url="Lead_Modifier.cfm?LeadID=#FORM.LeadID#"> 
<cfdump var="UPDATE COMMAND">
<cfelse>
 <!--- Add Lead --->
 <cfinsert datasource="#application.datasource#"
          tablename="leads"
          formfields="FirstName,
          				LastName,
                        Secondary_first,
                        Secondary_last,
                        Company,
                        HomePhone,
                        WorkPhone,
                        MobilePhone,
                        OtherPhone,
                        OtherPhoneLabel,
                        AltPhone,
                        AltPhoneLabel,
                        EmailAddress,
                        SecondEmail,
                        Website,
                        PropertyAddress,
                        City,
                        State,
                        ZipCode">
 <cfset action="ADDED">
  <!--- Get ID number of just-inserted lead--->
  <cfquery datasource="#application.datasource#" name="getNewLead">
   SELECT Max(LeadID) As NewID FROM leads
  </cfquery>
  
  <!--- Insert Lead Tracking--->
  <cfquery name ="addRecord" dataSource="#application.datasource#"> 
	   INSERT INTO lead_tracking (LeadID,Lead_SourceID,Lead_typeID,Lead_priorityID,CreationDate)
       VALUES (<cfqueryparam value="#getNewLead.NewID#" cfsqltype="cf_sql_varchar">,'#FORM.Lead_SourceID#','#FORM.Lead_typeID#','#FORM.Lead_priorityID#',#CreateODBCdate(FORM.CreationDate)#)
 </cfquery>
 
</cfif>

 <cflocation url="Lead_Modifier.cfm">

Open in new window

LVL 1
jasch2244Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
_agx_Connect With a Mentor Commented:
>> I do have a input tag with the name of CreationDate in the form

Oh wait ... I thought you said you DON'T have a field with by name.  

1) May as well try removing it and see if it works then.
2) Also, the docs say:

      "The formFields list must include the database table primary key field, which
       must be present in the form. It can be hidden..."

I don't see FORM.leadID in your field list. So you might add it and give that a try too.
0
 
_agx_Commented:
Your understanding of how it *should* work is correct.  I do recall a few bugs with cfupdate/cfinsert. But I think those applied to columns with similar names. Like if you had "CreationColumn" and "CreationDateColumn". It doesn't seem to apply in your case.

Is the CREATIONDATE column mandatory maybe?


>> <!--- Get ID number of just-inserted lead--->
>>  <cfquery datasource="#application.datasource#" name="getNewLead">
>>    SELECT Max(LeadID) As NewID FROM leads
>>   </cfquery>

That's not thread safe.  If you're using MS SQL, MySQL, etc... use the cfquery result attribute instead.
 
0
 
Brijesh ChauhanStaff IT EngineerCommented:
Do you get the same error if you using cfquery for insert and updates ?

Also, if you use cfquery, then you can eliminate the below query

 <!--- Get ID number of just-inserted lead--->
  <cfquery datasource="#application.datasource#" name="getNewLead">
   SELECT Max(LeadID) As NewID FROM leads
  </cfquery>

Just use the result attribute of cfquery tag,

<cfquery datasource="#application.datasource#" result = "whatever">
        -------- Query Insert SQL here ----------
</cfquery>

depending on your database, you can simply say to get the ID

SQL Server: whatever.IDENTITYCOL
MySQL: whatever.GENERATED_KEY
Sybase: whatever.SYB_IDENTITY
Informix: whatever.SERIAL_COL
Oracle: whatever.ROWID


0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jasch2244Author Commented:
Thanks all:
Seems to be the problem lie's in the update only.. the insert works perfectly. Thanks on the generated key / results idea... I still don't get how to use it in this instance as when I use cfquery for MySQL update or insert I'm getting some date issue even if I use CreateODBC date function. I know sounds goofy so I resulted to what I knew would work for the situation. Thank you for the suggestion though :)

Do you think DateCreated is some reserved name for a function? _agx not sure what you mean by mandatory. I don't think it is as it's just another input tag like the rest of the formfields. But it's not in the update or insert commands so I don't know why it would be glitching.
0
 
_agx_Commented:
If you're having this much trouble with cfupdate, I'd probably switch to a regular UPDATE instead.

>> when I use cfquery for MySQL update or insert I'm getting some date
>> issue even if I use CreateODBC date function

    What issues? Can you post the code you tried, and the error message? Assuming you're
    updating a "datetime" column,  you shouldn't have any problem with createODBCDate()
    OR cfqueryparam for that matter.

>> not sure what you mean by mandatory

      I mean does it allow you to leave it empty (or null)?  

_agx_ wrote:
> If you're using MS SQL, MySQL, etc... use the cfquery result attribute instead.
jasch2244 wrote:
>>> Thanks on the generated key / results idea... I still don't get how to use it in
>>> this instance


   Obviously it's only for inserts, and only for regular INSERT's. You can't use it with CFINSERT.
   But it's much safer than using SELECT MAX(...).  That will return the wrong ID under high load.
   Here's a simple example

   <cfquery name="addRecord" result="insertedRecord" datasource="...">
          INSERT INTO YourTable ( SomeColumn )
          VALUES ( 'something' )
    </cfquery>

    <cfoutput>The new record id is #insertedRecord.GENERATED_KEY#</cfoutput>

0
 
Brijesh ChauhanStaff IT EngineerCommented:
if it's a problem with update, then use CFABORT at line 31, so that the system does not CHECK the rest of the code.
0
 
Brijesh ChauhanStaff IT EngineerCommented:
For Update, you need the primary key of the table to be there, basically it needs to know which ID to update...
0
 
_agx_Commented:
>> so that the system does not CHECK the rest of the code

Sounds like it's a runtime (not compile) error, so that wont' have any effect. ie It'll just error out the same as it's doing now.
0
 
jasch2244Author Commented:
Thanks again _agx
0
 
jasch2244Author Commented:
I needed the pk (LeadID) in the formfield (cfupdate) which is weird due to the fact that I have it already as a hidden input tag.. should have picked it up.
0
 
_agx_Commented:
>> should have picked it up.

Yes but using "formfields" tells CF to ignore everything else in the FORM scope. So I guess if you want it to "see"  the LeadID field, you have to put it in the list.
0
 
jasch2244Author Commented:
Indeed! Thanks for the GeneratedKey tip I was able to convert from cfinput to SQL INSERT and used the result.GNERATEDKEY to pull the most recent insert. Thank you, thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.