每次
执行此语句时,我都必须递增数据库中的字段:
$sql="UPDATE `product` SET buyCount = buyCount+1 WHERE id=".$productID;
但它不起作用。有什么帮助吗?
我最好的猜测是 BuyCount 初始化为 NULL 而不是 0。 尝试:
set BuyCount = coalesce(BuyCount, 0) + 1
或者,您的 where 子句失败。 您可以尝试在另一列中设置一个值,以查看它是否正常工作。
将结束 " 移到查询的末尾,并将变量括在单引号中。
$sql="UPDATE product SET buyCount = buyCount+1 WHERE id='$productID'";
试试这个
$sql="UPDATE product SET buyCount = buyCount+1 WHERE id= $productID";