rick.emmet Posted February 17, 2015 Share Posted February 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
scootstah Posted February 17, 2015 Share Posted February 17, 2015 I would guess that you're either overwriting the session somewhere, not using session_start() appropriately, or some other math error resulting in 0. But without any code to look at, I'm just speculating here. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 17, 2015 Share Posted February 17, 2015 Is PHP set to display all errors and warnings? To do that, you could add the following to the top of your script(s): <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> Of course, you'll want to remove this code once you're done debugging. Quote Link to comment Share on other sites More sharing options...
rick.emmet Posted February 20, 2015 Author Share Posted February 20, 2015 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 20, 2015 Share Posted February 20, 2015 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. Quote Link to comment Share on other sites More sharing options...
rick.emmet Posted February 24, 2015 Author Share Posted February 24, 2015 Thanks Psycho, I haven't been able to get back to this for four days (yikes), but I'll start on it today. Cheers, Rick Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.