I am very new in php and mysql and I am trying to add a product to a cart. I think my code works fine except the part "quantitat+1". (If I just replace this for a number it works) I don't know how should I say that I want to update and add 1 the existing quantity whatever it is.
I get no error, so I don't know what's the problem. I tried ($row['quantitat'];)+1 and it doesn't work either
I'm an absolute beginner, so I suppose I'm making a very obvious mistake or there is something I don't understand.
if(isset($_GET["id"])) {
$result = mysql_query("SELECT * FROM carret
WHERE producte='".$_GET["id"]."'");
}
if (mysql_num_rows($result)>0) { // if already there is one or more
mysql_query("UPDATE carret SET quantitat = quantitat + 1
WHERE producte='".$_GET["id"]."'");
echo "UPDATE. I have added 1";
}else{
mysql_query("INSERT INTO carret (producte, quantitat)
VALUES (".$_GET["id"].",1)");
echo "INSERT. I have inserted one new product";
}