I have a shopping cart page which displays products from a database specific to the website user using a repeat region on a recordset.
The problem is i have an update button so they can change the quantity and a remove button so they can remove an item from the cart.
No matter how many products appear on the page the only product which is updated or removed is the first product displayed from the recodeset.
Please see code below;
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%><form action="<%=MM_editAction%>" METHOD="POST" name="form1"><tr><td class="image"><a href="shop.asp?sku=<%=Recordset1.Fields("sku")%>&sessionx= <%=Recordset1.Fields("sessionx")%>"> <img class="img-fluid" src="<%=(Recordset1.Fields.Item("image").Value)%>" alt=""/></a></td><td class="description"><a href="shop.asp?sku=<%=Recordset1.Fields("sku")%>&sessionx=<%=Recordset1.Fields("sessionx")%>"><%=(Recordset1.Fields.Item("name").Value)%></a></td><td class="price"> £<%=(Recordset1.Fields.Item("totalprice").Value)%></td><td class="td-quentety"><input type="number" value=" <%=(Recordset1.Fields.Item("qty").Value)%>" name="qty"></td><td class=""><a class="button mt-10" href="#" onclick="document.forms['form1'].submit(); return false;">Update</a><input type="hidden" name="MM_update" value="form1"><input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("idx").Value %>"></form></td><form ACTION="<%=MM_editAction%>" METHOD="POST" name="form2"><td class=""><a class="button mt-10" href="#" onclick="document.forms['form2'].submit(); return false;">Remove</a></td></tr><input type="hidden" name="MM_delete" value="form2"><input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("idx").Value %>"></form><%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>` <%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%><%
If (CStr(Request("MM_update")) = "form1") Then
If (Not MM_abortEdit) Then
' execute the update
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_Conn01_STRING
MM_editCmd.CommandText = "UPDATE lee2121.Cart SET qty = ? WHERE idx = ?"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("qty"), Request.Form("qty"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%><%
' *** Delete Record: construct a sql delete statement and execute it
If (CStr(Request("MM_delete")) = "form2" And CStr(Request("MM_recordId")) <> "") Then
If (Not MM_abortEdit) Then
' execute the delete
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_Conn01_STRING
MM_editCmd.CommandText = "DELETE FROM lee2121.Cart WHERE idx = ?"
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, Request.Form("MM_recordId")) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>