[英]sql update statement doesn't work
I have to increment a field in my DB each time I execute this statement:每次执行此语句时,我都必须增加数据库中的一个字段:
$sql="UPDATE `product` SET buyCount = buyCount+1 WHERE id=".$productID;
But it doesn't work.但它不起作用。 Any help ?
有什么帮助吗?
My best guess would be that BuyCount is initialized to NULL and not 0. Try:我最好的猜测是 BuyCount 被初始化为 NULL 而不是 0。尝试:
set BuyCount = coalesce(BuyCount, 0) + 1
Alternatively, your where clause is failing.或者,您的 where 子句失败。 You might try setting a value in another column to see if it is working.
您可以尝试在另一列中设置一个值以查看它是否有效。
将结束 " 移动到查询的末尾并将变量括在单引号中。
$sql="UPDATE product SET buyCount = buyCount+1 WHERE id='$productID'";
试试这个
$sql="UPDATE product SET buyCount = buyCount+1 WHERE id= $productID";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.