Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting records when checkboxes are checked!!! 1

Status
Not open for further replies.

cloudseven

Programmer
Mar 16, 2003
18
0
0
CA
hi there I have a checkbox for each item displayed which contains a cartid for each item. When a button is pressed, I have a function which takes all the values of the checked boxes, and go into the database and delete the items matching the cartid. I got it working, but it only works when a single checkbox is clicked. Not multiple ones. Here is my code, thank you. I'll keep playing around with it. Thanks.

***IF ?ACTION=DELETE***
Case "DELETE"
For intCheck = 1 To Request.Form("itemcheck").Count
oCart.Remove(Request.Form("itemcheck"))
next
************************

THIS IS THE FUNCTION BEING CALLED...

Public Function Remove(ByVal itemreference)
'deletes an item from a user's cart

if not bLoaded then
Remove = false
Exit Function
end if

On Error Resume Next
itemreference = clng(itemreference)
If Err Then
Remove = False
Exit Function
End If
On Error GoTo 0

if itemreference = 0 then
Remove = False
Exit Function
end if

On Error Resume Next
c.execute "DELETE FROM ShoppingCart_New WHERE cartitemid = " & _
itemreference & " AND usrsessid = '" & Request.Cookies("user") & "'"
If Err.Number <> 0 Then
Remove = false
sDBErr = Err.Description
Exit Function
End If
On Error GoTo 0
Remove = True
End Function
 
found something neat with sql and now I've replace the execute command with:


c.Execute &quot;DELETE FROM shoppingcart_new WHERE cartitemid IN (&quot; & itemreference & &quot;)&quot;

and took out the for loop:

Case &quot;DELETE&quot;
oCart.Remove(Request.Form(&quot;itemcheck&quot;))


still doesn't work...oh well, keep on working at it...
 
alright, I got it to work though I had to make a few changes. Here is the code!!! Can someone explain to me the error handling codes. Thanks!!!



Public Function Remove
'deletes an item from a user's cart

if not bLoaded then
Remove = false
Exit Function
end if

'HAD TO COMMENT THIS OUT OR ELSE WON'T WORK
'On Error Resume Next
'Request.Form(&quot;itemcheck&quot;) = clng(Request.Form(&quot;itemcheck&quot;))
If Err Then
Remove = False
Exit Function
End If
On Error GoTo 0


'HAD TO COMMENT THIS OUT OR ELSE WON'T WORK
'if Request.Form(&quot;itemcheck&quot;) = 0 then
' Remove = False
' Exit Function
'end if

On Error Resume Next
c.Execute &quot;DELETE FROM shoppingcart_new WHERE cartitemid IN (&quot; & Request.Form(&quot;itemcheck&quot;) & &quot;)&quot; & _
&quot; AND usrsessid = '&quot; & Request.Cookies(&quot;user&quot;) & &quot;'&quot;

If Err.Number <> 0 Then
Remove = false
sDBErr = Err.Description
Exit Function
End If
On Error GoTo 0
Remove = True
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top