Jump to content

Increase Number By Value Stored In Passed Variable


son
 Share

Recommended Posts

I have the following working code to add items to shopping basket:

f (isset($_REQUEST['do']) && ($_REQUEST['do'] == 'add')){	if (isset($_GET['id']))	{	$id = (int) $_GET['id'];		if ($id > 0)		{		$id_query = "SELECT product, price FROM products WHERE product_id = $id";		$id_result = mysqli_query ($dbc, $id_query);			if (mysqli_num_rows($id_result) == 1)			{			list ($product, $price) = mysqli_fetch_array($id_result, MYSQLI_NUM);				if (isset($_SESSION['cart'][$id]))				{				$_SESSION['cart'][$id]++;				echo "<p>Another copy of the following item has been added to your quote page:<br /> $product with a price of £$price.</p>\n";				}				else				{				$_SESSION['cart'][$id] = 1;				echo "<p>The following item has been added to your quote page:<br /> $product with a price of £$price.</p>\n";CODE
To add items with quantity works fine, but when user adds same item to basket the quantity from item page overrides the quantity instead of adding to it. The relevant line is:$_SESSION['cart'][$id]= +$qty2;How do you properly replace code that increases by one ($_SESSION['cart'][$id]= ++) to add number stored in $qty2?Son
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...