Can someone please tell me how to update more than one row in the database with one submit button click.<br>I have a page that allows the user to select which interests they like and each of these interests have to be individual rows.<br><br>Thanx for your help
<!--- Get many rows of data --->
<cfquery name="qryCustomer" datasource="aquatrac">
Select *
From tblCustomer
</cfquery>
<!--- Start a form out side a loop --->
<form action="rma.cfm" method="post">
<!--- Set a hidden variable with the amount of records shown --->
<cfoutput><input type="Hidden" name="RecordCount" value="#qryCustomer.RecordCount#"></cfoutput>
<!--- Start output INSIDE form tags. Lets say we have three form fields: ID, Desc, Status.
We name the form fields based off of what row they are in. If we have three rows, our fields would be:
id1, Desc1, Status1
id2, Desc2, Status2
id3, Desc3, Status3
--->
<cfoutput query="qryCustomer">
<input type="Hidden" name="id#CurrentRow#" value="#id#">
<input type="text" name="Desc#CurrentRow#" value="#Desc#">
<input type="text" name="Status#CurrentRow#" value="#Status#">
</cfoutput>
<!--- Have a single submit button outside the loop --->
<input type="Submit" value="Save All">
</form>
TEMPLATE TWO (Insert or Update Records):
<!--- Run loop: one for every row outputed earlier --->
Now all we need to do is create variables within the loop that is composed of a prefix ("form.formfield" and a suffix (i).
It is important to note that the prefix is a static string value (Notice in the code it is wrapped in quotes. This means that the
variable is assigned a literal value of form.whatever. The suffix however is a dynamic value. The value will be equal to the loop number.
So the first time that this loop is fired, the locID variable will be given the value of form.ID1. The possible confusing part at this point is
that locID is simply equal to the string form.ID1. But that string value happens to be the name of the form field that we are trying to evaluate.
So all we have to do at this point is use the evaluate function to give us the value of the form field form.ID1.
The main 'trick' in this script is assigning a literal string value that is the same as the form field that you want to evaluate.
--->
I am have a similar problem. I created a page that pulls up a list of records inside a form, with a text box that is filled with a number from the AbOrder field (used to rank results).
The idea is that the user can use this form to enter new numbers in the rank text box, which should update the individual records, allowing query results to have a new rank order.
I used your method above, but all it does is create NEW records, with only the two fields I am using in the form being filled, one of which is the StoryID field, which is "AutoNumber" and the primary key, and the AbOrder field.
Here is the code on the action page:
<cfloop index="i" from="1" to="#form.RecordCount#">
<cfset locStoryID = "form.StoryID" & i>
<cfset locAbOrder = "form.AbOrder" & i>
<cfquery name="Update_Abs#i#" datasource="MyDb">
INSERT INTO Stories
(StoryID, AbOrder)
VALUES
('#Evaluate(locStoryID)#', '#Evaluate(locAbOrder)#')
</cfquery>
</cfloop>
I want only to UPDATE the records that are returned inside the form. I tried changing the query on the action page to an UPDATE, but I get an error.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.