Skip to main content
Inspiring
August 1, 2008
Answered

dynamically updating a form

  • August 1, 2008
  • 3 replies
  • 390 views
Anyone know what I'm doing wrong? I have dynamic multiple rows being spit out into a form that I want to be able to go through the form, make my changes and use 1 submit button. Then I need to update those results in the database according to their id. I have the following code below, it doesn't throw errors but it won't update the database. Any help would be appreciated.

The Form

<cfform method="post" action="enterresults2.cfm">

<cfset howmany = 0>
<cfoutput query="qmembers">

<cfset howmany = howmany + 1>
<table style="border: 1px solid black;">
<tr>
<td style="border: 1px solid ##FA5A03;" valign="top" align="left">#firstname# #lastname# - #id#</td>
<td style="border: 1px solid ##FA5A03;" valign="top" align="left"><cfif startweight NEQ "">Start Weight: #startweight#<cfelse> </cfif></td>
<td style="border: 1px solid ##FA5A03;" valign="top" align="left"><cfif startbmi NEQ "">Start BMI: #startbmi#<cfelse> </cfif></td>
</tr>
<tr>
<td valign="top" colspan="3">
<cfif qchallenge.lengthofchallenge GTE 1>Week 1:
<input type="text" name="week1_#howmany#" size="2" value="#week1#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 2>Week 2:
<input type="text" name="week2_#howmany#" size="2" value="#week2#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 3>Week 3:
<input type="text" name="week3_#howmany#" size="2" value="#week3#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 4>Week 4:
<input type="text" name="week4_#howmany#" size="2" value="#week4#"></cfif>
<br><br>
<cfif qchallenge.lengthofchallenge GTE 5>Week 5:
<input type="text" name="week5_#howmany#" size="2" value="#week5#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 6>Week 6:
<input type="text" name="week6_#howmany#" size="2" value="#week6#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 7>Week 7:
<input type="text" name="week7_#howmany#" size="2" value="#week7#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 8>Week 8:
<input type="text" name="week8_#howmany#" size="2" value="#week8#"></cfif>
<br><br>
<cfif qchallenge.lengthofchallenge GTE 9>Week 9:
<input type="text" name="week9_#howmany#" size="2" value="#week9#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 10>Week 10:
<input type="text" name="week10_#howmany#" size="2" value="#week10#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 11>Week 11:
<input type="text" name="week11_#howmany#" size="2" value="#week11#"></cfif>
<cfif qchallenge.lengthofchallenge GTE 12>Week 12:
<input type="text" name="week12_#howmany#" size="2" value="#week12#"></cfif>

<input type="hidden" name="firstname_#howmany#" value="#firstname#">
<input type="hidden" name="lastname_#howmany#" value="#lastname#">
<input type="hidden" name="id_#howmany#" value="#id#">

</td>

</tr>
</table>

</cfoutput>
<cfoutput>#howmany#</cfoutput>
<input type="hidden" value="<cfoutput>#howmany#</cfoutput>" name="rowcount">
<input type="submit" value="Update Weights">
</cfform>

The Update Page

<cfloop from="1" to="#form.rowcount#" index="i">



<cfquery name="updatemembers" datasource="#Application.ds#">
UPDATE teammembers
SET firstname = '#FORM['firstname_' & i]#',
<cfif parameterexists(week1)>week1 = '#FORM['week1_' & i]#',</cfif>
<cfif parameterexists(week2)>week2 = '#FORM['week2_' & i]#',</cfif>
<cfif parameterexists(week3)>week3 = '#FORM['week3_' & i]#',</cfif>
<cfif parameterexists(week4)>week4 = '#FORM['week4_' & i]#',</cfif>
<cfif parameterexists(week5)>week5 = '#FORM['week5_' & i]#',</cfif>
<cfif parameterexists(week6)>week6 = '#FORM['week6_' & i]#',</cfif>
<cfif parameterexists(week7)>week7 = '#FORM['week7_' & i]#',</cfif>
<cfif parameterexists(week8)>week8 = '#FORM['week8_' & i]#',</cfif>
<cfif parameterexists(week9)>week9 = '#FORM['week9_' & i]#',</cfif>
<cfif parameterexists(week10)>week10 = '#FORM['week10_' & i]#',</cfif>
<cfif parameterexists(week11)>week11 = '#FORM['week11_' & i]#',</cfif>
<cfif parameterexists(week12)>week12 = '#FORM['week12_' & i]#',</cfif>
lastname = '#FORM['lastname_' & i]#'
WHERE id = #FORM['id_' & i]#
</cfquery>



</cfloop>
    This topic has been closed for replies.
    Correct answer Dan_Bracuk
    Turn on debugging and look at the sql that is being sent to your db. That generally yields a clue or two.

    3 replies

    Dan_BracukCorrect answer
    Inspiring
    August 4, 2008
    Turn on debugging and look at the sql that is being sent to your db. That generally yields a clue or two.
    brianismAuthor
    Inspiring
    August 4, 2008
    I did check this out, and it does print a message inside the loop. I can also loop the output of the form and it shows. It just won't update the table.
    Inspiring
    August 1, 2008
    brianism wrote:
    > it doesn't throw errors but it won't update the database

    Silly question, but did you first verify the loop is even executing? ie Print a message to the screen inside the loop so you can tell it is executing.