Jump to content

How to deal with session shopping cart.


sgt.virus

Recommended Posts

Hi,

 

Ive created a shopping cart using php sessions. The only problem Ive got now, is how to send the cart to a email address. The way its set up at the moment, it sends a email for each line in the cart, not all in one email.

 

This is the bit of the code:

	while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {


	$subtotal = $_SESSION['cart'][$row['id']]['quantity'] * $row['cost'];
	$total += $subtotal;


	echo "	<tr>
	<td align=\"left\">{$row['id']}</td>
	<td align=\"left\">{$row['name']}</td>
	<td align=\"left\">{$row['amount']}</td>
	<td align=\"right\">£{$row['cost']}</td>
	<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['id']}]\" value=\"{$_SESSION['cart'][$row['id']]['quantity']}\" /></td>
	<td align=\"right\">£" . number_format ($subtotal, 2) . "</td>
</tr>\n";
$ses = $_SESSION['cart'][$row['id']]['quantity'];
$cartt = (int) 0;
for ($i = 0; $i < count ($_SESSION['cart']); $i++) {
    $cartt = $cartt + $_SESSION['cart'][$i]['quantity'];
$ctotal = $cartt + $ses;
$p =(ceil($ctotal / 12))*9;
$t = $total + $p;
$to = "[email protected]";
$subject = "New Order";
$message = $row['id'];
}
$emailmessage = "Product name: ". $message . " Quantity: ". $ses ."<br />";
echo $emailmessage;
mail($to,"Order",$emailmessage,"[email protected]");

 

So for example, say Ive got 3 different products in the cart, the code above will send a email for each product in the cart, not all in one email which I want it to do.

 

Any advice or code I could use to solve this problem would be greatly appriciated.

 

Scott.

 

Link to comment
https://forums.phpfreaks.com/topic/151419-how-to-deal-with-session-shopping-cart/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.