Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Update question


Message #1 by "Ian Richardson" <ian@i...> on Mon, 17 Jun 2002 12:35:38
Hi,
This is a really dumb question but it has got me stumped!
I am building a small shopping cart and I have a dynamically generated 
list/form of the users's selected items and I want to allow them to be 
able change quanities in any/all item/s in their list and update all item 
quantities at the same time using one update button.

My question is how can I loop through the list/form and update each record.
My code is below which does not update the database:


I apologise for this question I feel I should be able to suss this but I 
just cannot get it.

Cheers

ian


If Request.form("update") = "yes" Then

For each Item In Request.Form

strUID = Request.Form("txtUID")
strItem = Request.Form("txtItem")
strPrice = Request.Form("txtPrice")
strQuantity = Request.Form("txtQuantity")
strDatePurchased = date()

strSQL = "SELECT * FROM tblBasket  WHERE UID = '" & strUID & "' AND 
BasketID = ' " & strBasketID &"' "
NewItem.Open strSQL, con, adOpenStatic, adLockOptimistic


NewItem.Update
NewItem("BasketID") = Session("BasketID")
NewItem("Item") = strItem
NewItem("Price") = (strPrice)
NewItem("TransactionValue") = (strPrice * strQuantity)
NewItem("Quantity") = strQuantity
NewItem("DatePurchased") = strDatePurchased
NewItem.update
response.write strItem & "<br>"
response.write strprice & "<br>"
response.write strQuantity & "<br>"

Next

Response.Redirect "basket.asp"
Else
Set viewbasket = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblBasket  WHERE BasketID = '" & strBasketID & "'"
viewbasket.Open strSQL, con, adOpenStatic, adLockOptimistic
End If


 
Message #2 by "Ken Schaefer" <ken@a...> on Tue, 18 Jun 2002 09:01:59 +1000
Create hidden inputs to store the Record IDs. These hidden input(s) should
have the same *name*.

Create the checkboxes with the name based on the record ID, and the value
equal to however many items the user has, eg:

<!-- Name is the same, value is recordID -->
<input type="hidden" name="RecordID" value="1">
<input type="hidden" name="RecordID" value="2">
<input type="hidden" name="RecordID" value="3">

<!-- Name based on recordID, value is quantity>
<input type="checkbox" name="Quant_1" value="6">
<input type="checkbox" name="Quant_2" value="18">
<input type="checkbox" name="Quant_3" value="42">

Then on the processing ASP page you can do:

<%
If Request.Form("RecordID").Count > 0 then

    For Each x in Request.Form("RecordID")

        Response.Write(x & " = " & Request.Form("Quant_" & x) & "<br>")

    Next

End If
%>

Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Ian Richardson" <ian@i...>
To: "Access ASP" <access_asp@p...>
Sent: Monday, June 17, 2002 12:35 PM
Subject: [access_asp] Update question


: Hi,
: This is a really dumb question but it has got me stumped!
: I am building a small shopping cart and I have a dynamically generated
: list/form of the users's selected items and I want to allow them to be
: able change quanities in any/all item/s in their list and update all item
: quantities at the same time using one update button.
:
: My question is how can I loop through the list/form and update each
record.
: My code is below which does not update the database:
:
:
: I apologise for this question I feel I should be able to suss this but I
: just cannot get it.
:
: Cheers
:
: ian



  Return to Index