lewisstevens1 Posted June 21, 2012 Share Posted June 21, 2012 Hiya guys, I have this script i have wrote, it seems to work although there's a little problem. <?php include 'login/dbc.php'; page_protect(); if (isset($_SESSION['user_id'])) { $user = $_SESSION['user_id']; $quantity = $_POST["postquantity"]; $prod_id = $_POST["postname"]; $rs_duplicate = mysql_query("select count(*) as total from cart where product_id='$prod_id' AND cart_user=".$_SESSION['user_id']."") or die(mysql_error()); $result = mysql_query("SELECT * FROM cart WHERE product_id='$prod_id' AND cart_user=".$_SESSION['user_id'].""); list($total) = mysql_fetch_row($rs_duplicate); if ($total > 0) { while($row = mysql_fetch_array($result)) { $tot_quantity = $quantity + $row['quantity']; mysql_query("UPDATE cart SET quantity='$tot_quantity' WHERE cart_user=".$_SESSION['user_id']." AND product_id='$prod_id'"); echo "#". $tot_quantity; } } else { mysql_query("INSERT into cart ( cart_user, product_id, quantity ) VALUES ( '$user', '$prod_id', '$quantity' ) "); } echo "Product ID: $prod_id"; echo "<br>quantity_calc: ".$quantity_calc." <br>"; echo "Quantity: $quantity"; echo "<br><br>"; echo " i need to select the productid, we will then use this to insert into cart. also insert our userid into cart user "; }else{ echo "no stop!"; }?> This is just ment to check if the product allready exists and then update depending on the value thats sent to it... Now it does work, theres just one problem though.. It randomly when changing the values on the two products i have in the database, it decides to update both... Although most of the time it works.. Why is it that it randomly does it?? Many thanks Lewis Stevens Link to comment https://forums.phpfreaks.com/topic/264547-php-shopping-cart/ Share on other sites More sharing options...
lewisstevens1 Posted June 22, 2012 Author Share Posted June 22, 2012 Anyone have an idea :/ Im thinking it must have something to do with the mysql query lines lol but i swear thats only pointing to one record..? Link to comment https://forums.phpfreaks.com/topic/264547-php-shopping-cart/#findComment-1356070 Share on other sites More sharing options...
lewisstevens1 Posted June 25, 2012 Author Share Posted June 25, 2012 Ah sorted it thanks Link to comment https://forums.phpfreaks.com/topic/264547-php-shopping-cart/#findComment-1356798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.