xgd Posted March 17, 2010 Share Posted March 17, 2010 Hello, I am making a shopping cart, and basically i got stuck. I do not know how to pass the value of the $total variable (which contains the order total) from view_cart.php to the checkout.php page so i can store it in a database. Can someone please help me with that ? I get the $total like this: $subtotal = $_SESSION['cart'][$row['print_id']]['quantity'] * $_SESSION['cart'][$row['print_id']]['price']; $total += $subtotal; So how do i know pass that $total variable to another page (in this case checkout.php) so i can freely use it ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/195557-passing-a-value-through-sessions/ Share on other sites More sharing options...
JonnoTheDev Posted March 17, 2010 Share Posted March 17, 2010 Simple answer, you dont need to. You cart contents are already contained within a session. Simply write a simple function that gives you the cart total that you can call on any page. Loop through the cart items price and times by the quantity. There is your total. You have already posted part of the code. Sessions persist throught a script (as long as you have called session_start()) until they are destroyed i.e You will destroy the shopping cart session after the user has paid for their items. You would never send prices, totals, etc through the url. This can be easily manipulated and users could end up paying nothing for the items in their cart. Quote Link to comment https://forums.phpfreaks.com/topic/195557-passing-a-value-through-sessions/#findComment-1027595 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.