gilabola Posted March 27, 2010 Share Posted March 27, 2010 This is what i want the process to be – once the user click the ‘addbtn’, the system will first check whether the product is already in the table ‘cart’ by comparing the PRO_ID. If the PRO_ID is not in the table, PRO_ID,PRO_NAME,PRO_PRICE,MEM_ID,CART_QUANTITY will be inserted to the table. But if the PRO_ID already exist in the table, it will only update the table by only adding 1 to the CART_QUANTITY The problem now, the system still inserting the PRO_ID,PRO_NAME,PRO_PRICE,MEM_ID,CART_QUANTITY to the table even when the same PRO_ID and MEM_ID exist in the table. I attached the jpeg example of the table. Please guide me. Thank you <?php if (isset($_POST["addcart"])) { $result2 = mysql_query("select PRO_ID from cart where PRO_ID = $PRO_ID and MEM_ID = $memid"); if ($result2 == 0) { $PRO_ID=$_POST["Product_ID"]; $PRO_NAME=$_POST["Product_Name"]; $PRO_PRICE=$_POST["Product_Price"]; mysql_query("insert into cart (PRO_ID,PRO_NAME,PRO_PRICE,MEM_ID,CART_QUANTITY) values ('$PRO_ID','$PRO_NAME',$PRO_PRICE,$memid,1)"); header ("Location:member_carts.php"); } else if (result2==$PRO_ID) { // update product quantity in cart table mysql_query("UPDATE cart SET CART_QUANTITY = CART_QUANTITY + 1 WHERE MEM_ID = '$memid' AND PRO_ID = $PRO_ID"); header ("Location:member_carts.php"); } } ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/196712-help-data-cant-be-updated-to-table/ Share on other sites More sharing options...
DaiLaughing Posted March 28, 2010 Share Posted March 28, 2010 You are using your product id variable before it contains anything. Quote Link to comment https://forums.phpfreaks.com/topic/196712-help-data-cant-be-updated-to-table/#findComment-1032925 Share on other sites More sharing options...
PFMaBiSmAd Posted March 28, 2010 Share Posted March 28, 2010 mysql_query() returns a result resource for a SELECT query that executes without any errors, not actual data. You must fetch data from a result resource or you can also use functions like mysql_num_rows() to find out how many rows are contained in a result set. These are the basics for using php/mysql that are covered in all the books, tutorials, and the php.net documentation for what you are attempting to do. Quote Link to comment https://forums.phpfreaks.com/topic/196712-help-data-cant-be-updated-to-table/#findComment-1032961 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.