Having real problems with deleting records

Results 1 to 3 of 3

Thread: Having real problems with deleting records

  1. #1
    Adam McKee Guest

    Default Having real problems with deleting records

    I posted before, but I need to post again to more clearly explain the problem. I&#039ve built a shopping cart system (your basic small shopping cart). On the "cart" page itself, users can remove a single item from the cart by clicking "remove" or by entering a quantity of "0" for the item. They can also remove multiple items at a time by entering "0" for each item , then clicking the update cart button.<BR><BR>The problem comes in where more often than not, when the Update Cart button is pressed, I get a message stating that the Record has already been deleted. When a user presses the "Update Cart" button, the values are passed to "cartupdate.asp" which does a FOR/NEXT loop based on how many items there are in the cart (i.e. 5 items, then FOR i = 1 to 5, except it&#039s dynamic because the line really reads FOR i = 1 to Request.Form("itemcount"). The logic I"m using is as follows:<BR><BR>&#060;% If Request.Form(currentitemqty) = 0 Then %&#062;<BR><BR>&#060;%<BR>Set Conn = Server.CreateObject("ADODB.Connection")<BR>Conn.Op en "database"<BR>vSQL = "DELETE * FROM Temp WHERE SessionID = &#039" & Session.SessionID & "&#039 AND ProductNum = &#039" & Request.Form(currentitemnum) & "&#039"<BR>Set RS = Conn.Execute(vSQL)<BR>%&#062;<BR><BR>&#060;% Else %&#062;<BR><BR>... the else goes on to actually update items that have increased or decreased quantities, followed by a NEXT to begin the loop again.<BR><BR>Can anyone see a problem with this? It&#039s almost as though the system, while in the loop, is thinking that it&#039s trying to delete the same record again, which I don&#039t fully understand.<BR><BR>Any help is appreciated, I&#039d be more than willing to let someone in to see what I&#039m talking about, or look at the full source code. I&#039ve tried the Response.Expires thing, which doesn&#039t seem to help (someone else suggested that)<BR><BR>Thank you!

  2. #2
    Join Date
    Dec 1969

    Default RE: Having real problems with deleting records

    can you show me the loop code, and the increment code for variable &#039currentitemnum&#039<BR><BR>j

  3. #3
    J Sodeman Guest

    Default RE: Having real problems with deleting records

    Well, I&#039m not sure of the specific problem with your code, but it is at least inefficient in the number of times it executes database calls. I would try something more like this:<BR><BR>&#060;% <BR> sDelete = ""<BR> If Request.Form(currentitemqty) = 0 Then %&#062; <BR>&#060;%<BR> if not isempty(sDelete) then sDelete = sDelete & ","<BR> sDelete = sDelete & "&#039" & Request.Form(currentitemnum) &"&#039"<BR>%&#062;<BR>&#060;% Else %&#062;<BR><BR>&#060;% End If %&#062;<BR>(end loop)<BR>&#060;%<BR>if not isempty(sDelete) then <BR> Set Conn = Server.CreateObject("ADODB.Connection") <BR> Conn.Open "database" <BR> vSQL = "DELETE FROM Temp WHERE SessionID = &#039" & Session.SessionID & "&#039 AND ProductNum IN (" & sDelete & ")" <BR> Conn.Execute vSQL<BR> Conn.close<BR>end if<BR>%&#062; <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts