Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/195557-passing-a-value-through-sessions/
Share on other sites

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.

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.