I am creating a website with shopping cart, I managed successively add items to basket, but i want the baskets in items to be inserted into orders table in my database at the same time, which works but every time i refresh a page or move around different pages the same items that are currently inside the basked are constantly inserted.
I am allow user to delete items from basket but again i want the same to happen in my database table.
Here is my code please analyze it and point out a solution THX.
cart.php:
if (isset($_GET['add'])){
$quantity = mysql_query('SELECT product_id, product_qua FROM products WHERE product_id='.$_GET['add']);
while($quantity_row = mysql_fetch_assoc($quantity)){
if($quantity_row['product_qua'] !=$_SESSION['cart_'.$_GET['add']]){
$_SESSION['cart_'.$_GET['add']]+='1';
}
}
}
if (isset($_GET['add'])){
$qq = mysql_query('SELECT * FROM users');
while($user_rows = mysql_fetch_assoc($qq)){
$grr = $_SESSION['username'];
if($user_rows['username'] == $grr){
$z = $user_rows['first_name'];
$zz = $user_rows['last_name'];
}
}
$q = mysql_query('SELECT product_name, product_qua, product_price from products WHERE product_id='.$_GET['add']);
while($prod_rows = mysql_fetch_assoc($q)){
$x = $prod_rows['product_name'];
$xx = $prod_rows['product_price'];
$xxx = $prod_rows['product_qua'];
$order = "INSERT INTO orders (order_user_first_name, order_user_last_name, order_product_name, order_product_price, order_product_quantity ) VALUES ('$z','$zz','$x','$xx','$xxx')";
mysql_query($order);
}
}
if(isset($_GET['remove'])){
$_SESSION['cart_'.$_GET['remove']]--;
}
The above code is not all the code from the file but the parts that are responsible of what I am trying to implement
Regards