Jump to content

Best upproach to updating


rick.emmet

Recommended Posts

Hello All,
I'm attempting to create functionality that allows users to update a sales figure by: adding one of two ad-ons (or both) and / or subtracting a promotional discount if one applies. I'm setting both of my ad-on variables, as well as the discount to zero, then I'm using plain PHP to process the math.

When I first arrive on the page, from an editing page, the correct figure is displayed at the bottom of the form ($9.99), but when I click on the recalculate button (form action=”THIS_PAGE”) the base price disappears and the total at the bottom becomes “$0.”

These are $_SESSION variables, so it seems to me that they should remain persistent. I've been looking at JavaScript DOM Storage shopping carts, and the use of multidimensional arrays such as $_SESSION['cart'] to solve this problem. It seems to me that this should be very straightforward, but perhaps I'm approaching this incorrectly.

I would like to get input on the best approach to this problem – don't even want to bother anyone with code at this point. Do any of you have a very reliable approach or model to suggest? Thanks a bunch in advance.
Cheers,
Rick

Link to comment
Share on other sites

Hello scootstah and cyberRobot,

Thank you for the replies! My service provider has been changing out their equipment and I haven't had access for several days. I may be overwriting the session somehow, didn't even occur to me to look into that and I'm not generating any errors at all. When I have a problem this messed up, it's ussually a matter of having the wrong approach, so that's why I didn't post any code. Is there a type of functionality that either of you prefer to use in this kind of situation? Thanks again!

Cheers,

Rick

Link to comment
Share on other sites

Sessions would normally be the way to go for 'cart' type data. I would almost always put the cart data in it's own subkey of the session array that way you can keep it separate from other session data you may want to keep.

 

To debug your problem run this at the top of the page

 

echo "<pre>" . print_r($_SESSION, 1) . "</pre>";

 

That will verify the values inside session before you run any logic on them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.