co.ador Posted September 5, 2009 Share Posted September 5, 2009 function AddItem($itemId, $qty) $result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); $row = mysql_fetch_row($result); $numRows = $row[0]; if($numRows == 0) { // This item doesn't exist in the users cart, // we will add it with an insert query @mysql_query("INSERT INTO cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)"); } else { // This item already exists in the users cart, // we will update it instead function UpdateItem($itemId, $qty); mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); } function RemoveItem($itemId) { mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); } Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 function AddItem($itemId, $qty) $result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); $row = mysql_fetch_row($result); $numRows = $row[0]; if($numRows == 0) { // This item doesn't exist in the users cart, // we will add it with an insert query @mysql_query("INSERT INTO cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)"); } else { // This item already exists in the users cart, // we will update it instead function UpdateItem($itemId, $qty); mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); } function RemoveItem($itemId) { mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); } You are missing brackets: function AddItem($itemId, $qty){ $result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); $row = mysql_fetch_row($result); $numRows = $row[0]; if($numRows == 0) { // This item doesn't exist in the users cart, // we will add it with an insert query @mysql_query("INSERT INTO cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)"); } else { // This item already exists in the users cart, // we will update it instead UpdateItem($itemId, $qty); mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); } function RemoveItem($itemId) { mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); } Also, to call a function, you don't state "function UpdateItem();" but rather "UpdateItem();" Quote Link to comment Share on other sites More sharing options...
co.ador Posted September 5, 2009 Author Share Posted September 5, 2009 Can you please sing where am I missing brackets please? Quote Link to comment Share on other sites More sharing options...
Batosi Posted September 5, 2009 Share Posted September 5, 2009 Err when he posted your code a second time he fixed it up. Quote Link to comment Share on other sites More sharing options...
co.ador Posted September 5, 2009 Author Share Posted September 5, 2009 ok I saw the opening bracket was not present thank you... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.