I am a newbie to mysql. I am making a table named inventory with 4 columns- id,name, price,quantity. Now if name already exists, I am to add the quantity to existing one else create a new row. (name is defined as UNIQUE). I am doing this on php. $name, $quant,$price contain the values.
mysqli_query($con,"INSERT INTO inventory (Name, Quantity, Price) VALUES ($name,$quant,$price)
ON DUPLICATE KEY UPDATE
Quantity = Quantity + $quant ,
Price = VALUES(Price) ");
I am unable to understand why it's not working correctly. Sometimes Quantity updates correctly, most of the times it doesn't. Rest everything working perfectly. Just the problem with Quantity. Thanks for any help
EDIT: I defined the table on phpmyadmin. Here are the details:
1 id int(11) AUTO_INCREMENT PRIMARY
2 Name varchar(15) latin1_swedish_ci UNIQUE
3 Quantity int(11)
4 Price int(11)
EDIT: It was a cache problem . SOLVED
SHOW CREATE TABLE inventory)