Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Mysql New Row Inserted into database table every time i refresh the page
    text
    copied!<p>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.</p> <p>I am allow user to delete items from basket but again i want the same to happen in my database table.</p> <p>Here is my code please analyze it and point out a solution THX.</p> <p>cart.php:</p> <pre><code>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']]--; } </code></pre> <p>The above code is not all the code from the file but the parts that are responsible of what I am trying to implement</p> <p>Regards </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload