SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP shopping cart help

    I'm building a shopping cart in asp and need some help.

    I have designed it so that with each new entry into the cart is a new entry to a array this array will be saved to an session variable.

    However i have not implemented all of this i'm just trying to create an array that will increase with the value x (a variable that increases by 1 every time a new entry to the array is added. )

    I cannot seem to get it working. The error i have is this

    Microsoft VBScript runtime error '800a0009'

    Subscript out of range

    /20509703/cart.asp, line 15


    here is my code.

    Code:
    <html>
    <body>
    <&#37;
    Dim product
    Dim myArray() 
    product = request.querystring(product_ID)
    Dim x 
    x= 0
    
    if product <> "" then
    
    myArray(0)="something"
    
    	Do while x >=""
    			myArray(x)=product
    
    			For i=0 to x
    
    			Set ORSp=server.createobject("ADODB.Connection")
    			ORSp.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("20509703.mdb") 
    			Set cart = Server.CreateObject("ADODB.Recordset")
    			sqltext="Select * from products where product_ID ="& myArray(i)
    			cart.Open sqltext, ORSp
    
    			while Not cart.EOF
    
    			   response.write(cart("PName")&"<br />")
    
    			cart.movenext
    
    			wend
    			Next 
    	x=x+1
    	Redim PRESERVE myArray(x)  
    	Loop 
    else 
    
    	response.write("you have nothing in your cart")
    End If
    
    %>
    </body>
    </html>
    The highlight in green is line 15 but,
    I think my problems arise in the parts highlighted in red. The variable x perhaps should be set to nothing and the do while loop maybe should be a for loop. "Redim PRESERVE myArray(x)" Here i'm trying to save all the previous entries and resize the array to x that has been incremented by 1 for the next entry, is it in the right place?

    help appreciated.

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I found this older thread

    I found this older thread that does what i want however, wandered if someone could explain to me how i can use the sub in it Sub AddDictionary(oDict)
    here is the link

    http://www.sitepoint.com/forums/show...tionary+object

    The entries are still static and i cant figure out how to add new entries if a variable is passed through the URL?


Bookmarks

Posting Permissions

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