Jump to content

HELP: Data can't be updated to table


gilabola

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/196712-help-data-cant-be-updated-to-table/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.