943,796 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Marked Solved
  • Views: 913
  • ColdFusion RSS
May 19th, 2009
0

Data Update Fails

Expand Post »
Can someone please help me figure out what I am doing wrong? Basically I have a form where users enter a bunch of values. On submit, the form values are dumped into a table in the DB.

The process is as follows: Users enter a set of values TWICE for the same ID using the same form. If the frist two values match, then a 3rd set is auto-updated (the user doesn't have to hand-enter the values this time; the UPDATE of the DB is to be done automatically). If they do not match, then the user sees the form a 3rd time. Basically, the 3rd set is the one that is critical and one that will be used for further calculations.

My code fails at the comparison + Auto-Update stage. i.e. if the 2 values match, the 3rd value isn't automatically entered. Anyone know what I am missing?

Here's my code:
-------------------------------------------------------------------------------
ColdFusion Syntax (Toggle Plain Text)
  1. <cfquery name = "getValues"> <!--- Get required values for this ID --->
  2. SELECT column1, column2, column3
  3. FROM tableName
  4. WHERE ID = #URL.ID#
  5. </cfquery>
  6.  
  7. <cfoutput query = "getValues">
  8. <cfif column1 EQ "">
  9. <cfquery name = "updateValue1">
  10. UPDATE tableName
  11. SET column1 = #FORM.field#
  12. WHERE ID = #URL.ID#
  13. </cfquery>
  14. <cfelseif column2 EQ "">
  15. <cfquery name = "updateValue2">
  16. UPDATE tableName
  17. SET column2 = #FORM.field#
  18. WHERE ID = #URL.ID#
  19. </cfquery>
  20.  
  21. <cfquery name="compareValues"> <!--- Compare Values 1 and 2 --->
  22. SELECT column1, column2
  23. FROM tableName
  24. WHERE ID = #URL.ID#
  25. </cfquery>
  26.  
  27. <cfif #compareValues.column1# EQ #compareValues.column2#>
  28. UPDATE tableName
  29. SET column3 = #compareValues.column2#
  30. WHERE ID = #URL.ID#
  31. </cfif>
  32.  
  33. <cfelseif ((column3 EQ "NULL") OR (column1 NEQ column2))>
  34. <cfquery name = "updateValue3">
  35. UPDATE tableName
  36. SET column3 = #FORM.field#
  37. WHERE ID = #URL.ID#
  38. </cfquery>
  39. </cfif>
  40. </cfoutput>
-----------------------------------------------------------------------------

BTW, the reason behind entering the data multiple times for the same ID is to make sure we have the correct values. The idea being that the at least one of the 3 values will be correct. If anyone has a better algorithm for achieving this, please let me know.

FYI, I am using CF MX7 and SQL Express 2005.

TIA!
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
SQL_n00b is offline Offline
23 posts
since Apr 2009
May 20th, 2009
0

Re: Data Update Fails

Here's what I just found:

If I include a statement like Today is <cfoutput>#Now()#</cfoutput> just before the
<cfif #compareValues.column1# EQ #compareValues.column2#> loop begins, I see the timestamp on the second iteration.

That leads me to believe that even before the query named updateValue2 is run, the code execution has already proceeded to the Today is #Now()# statement. So it turns out there is an error in the logic flow.

How do I fix this?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
SQL_n00b is offline Offline
23 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: Cfdirectory issue
Next Thread in ColdFusion Forum Timeline: Convert Docx and doc to HTML in unix environment with CFMX7





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC