Jump to content

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
https://forums.phpfreaks.com/topic/294656-best-upproach-to-updating/
Share on other sites

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.

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

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.

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.