Data Update Fails

Thread Solved

Join Date: Apr 2009
Posts: 16
Reputation: SQL_n00b is an unknown quantity at this point 
Solved Threads: 1
SQL_n00b's Avatar
SQL_n00b SQL_n00b is offline Offline
Newbie Poster

Data Update Fails

 
0
  #1
May 19th, 2009
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:
-------------------------------------------------------------------------------
  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!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 16
Reputation: SQL_n00b is an unknown quantity at this point 
Solved Threads: 1
SQL_n00b's Avatar
SQL_n00b SQL_n00b is offline Offline
Newbie Poster

Re: Data Update Fails

 
0
  #2
May 20th, 2009
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?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC