Shopping cart problem


#1

Hi just wondering if anyone can help me. i am trying to get a shopping cart working and am having a few problems. on the webpage the user has 2 option to rent or buy. the problem that i am having is that if i click rent, it adds the rental and buy option to the shopping cart, the same thing happens if i click the buy button.

The Hangover Part II x 1@ €3.99= €3.99[-] [+] [Delete]
The Hangover Part II x 1@ €7.99= €7.99[-] [+] [Delete]

Total: €11.98

I have tried everything i can think of but cant get it working properly can anyone help please. the code follows

[php]

<?php session_start(); $page = 'index2.php'; if(isset ($_GET['addrent']) ){ $quantity = mysql_query('SELECT id, quantity FROM movies WHERE id='.mysql_real_escape_string((int)$_GET['addrent'])); while($quantity_row = mysql_fetch_assoc($quantity) ){ if($quantity_row['quantity'] != $_SESSION['cart2_'.(int)$GET['addrent'] ]) { $_SESSION['cart2_'.(int)$_GET['addrent']] +='1'; } } header('Location: '.$page); } if(isset ($_GET['addbuy']) ){ $quantity = mysql_query('SELECT id, quantity FROM movies WHERE id='.mysql_real_escape_string((int)$_GET['addbuy'])); while($quantity_row = mysql_fetch_assoc($quantity) ){ if($quantity_row['quantity'] != $_SESSION['cart2_'.(int)$GET['addbuy'] ]) { $_SESSION['cart2_'.(int)$_GET['addbuy']] +='1'; } } header('Location: '.$page); } if(isset($_GET['remove']) ) { $_SESSION['cart2_'.(int)$_GET['remove']]--; header('Location: '.$page); } if(isset($_GET['delete']) ) { $_SESSION['cart2_'.(int)$_GET['delete']]='0'; header('Location: '.$page); } function products() { $get = mysql_query("SELECT image, id, name, description, rent FROM movies WHERE quantity > 0 ORDER BY id DESC " ); if(mysql_num_rows($get) == 0){ echo "there are no products to display"; }else{ while($get_row = mysql_fetch_assoc($get) ){ $get_row['name']; $get_row['description']; $get_row['image']; $get_row['rent']; $name = $get_row['name']; $description = $get_row['description']; $image = $get_row['image']; $rent_price = '€'.number_format($get_row['rent'], 2); $add = 'Rent'; $add1 = 'buy'; $picture = ''; echo "
$picture

$name

$description 
Rent $rent_price $add $add1
"; } } } function cart() { $sub = ""; $sub2 = ""; $total=""; foreach($_SESSION as $name => $value){ if($value > 0) { if(substr($name, 0, 6)=='cart2_'){ $id = substr($name, 6, (strlen($name)-6)); // allows is to take the exact number from cart_ $get = mysql_query('SELECT id, name, rent FROM movies WHERE id='.mysql_real_escape_string((int)$id) ); // int means interger is only being passed for secuirty; while ($get_row = mysql_fetch_assoc($get) ){ $sub = $get_row['rent']*$value; echo $get_row['name'].' x '.$value.'@ €'.number_format($get_row['rent'], 2).'= €'.number_format($sub,2).'[-] [+] [Delete]
'; } } if(substr($name, 0, 6)=='cart2_'){ $id = substr($name, 6, (strlen($name)-6)); // allows is to take the exact number from cart_ $get = mysql_query('SELECT id, name, buy FROM movies WHERE id='.mysql_real_escape_string((int)$id) ); // int means interger is only being passed for secuirty; while ($get_row = mysql_fetch_assoc($get) ){ $sub2 = $get_row['buy']*$value; echo $get_row['name'].' x '.$value.'@ €'.number_format($get_row['buy'], 2).'= €'.number_format($sub2,2).'[-] [+] [Delete]
'; } } $total += ($sub+$sub2); } } if($total==0){ echo "Your cart is empty"; }else{ } ?>

[/php]