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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP PLEASE!!!! Be warned though.. Dictionary Object!!

Status
Not open for further replies.

JonMusto

Programmer
Aug 3, 2004
34
GB
Hi All,

Can someone please help me...

For my Uni project i'm comparing PHP to ASP... I've written a simple e-commerce site in PHP with user log-in area, and shopping cart... etc... To do the shopping cart I simply stored an associative array in a session variable, with product id as the key, and quantity as the value... And it works a treat...

Which brings me to my ASP version... I've replicated everything i've done in the PHP site perfectly except for one section... The shopping cart... The only thing i can think that is close to an associative array in ASP is the Dictionary Object.

Which is where my problems begin.

I am starting my object in the global.asa as follows:

<object runat=server scope=session id=basket progid="scripting.dictionary"></object>

Then using the different methods on it.. through my shopping cart functions... One function in particular:

function addItem(prod_id, quantity)
basket.item(prod_id) = quantity
end function

This passes in a product id and a quantity, and sets a dictionary key accordingly... if that key exists it should change the value to the new 'quantity', and if it doesn't exist it should set a new key with that value (according to the books)... looks simply enough, but isn't working...

If i add 1 item of a particular product, it adds it fine... If i then try to change it to have a quantity of 3, it seems to create another row, of the same product, but with 3 as its quantity....
i.e

prod_id quantity
4 1

then change the amount... and the cart shows...

prod_id quantity
4 1
4 3

And my delete_item function.....

function deleteItem(prod_id)
basket.remove(prod_id)
end function

returns this error...

Error Type:
Microsoft VBScript runtime (0x800A802B)
Element not found
/ASP/basketfunctions.asp, line 7

Has anyone had this problem before... PLEASE HELP ME!!!!!
 
I've sussed it....

This may be of interest to those who use, or are thinking of using dictionary objects.
When I changed my product id to a string before adding to the dictionary cstr(prod_id).. It fixed it.... YEY!!! There must be a bug with using integers i guess...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top