在mysql / php中增加字段默认值

时间:2013-04-20 08:12:30

标签: php mysql increment

$saa = "update  aspirantdt set vote = 'vote'+1 where 'post_id' = '$id' ";

当我检查数据库时,值没有增加。 帮助我。

4 个答案:

答案 0 :(得分:1)

yuo在update查询中出现语法错误,您使用的是引号而不是反引号。对列名称和引号使用反引号尝试更改如下

$saa = "update  `aspirantdt` set `vote` = (`vote`+1) where `post_id` = '".$id."' ";

答案 1 :(得分:1)

只需删除引号或使用反引号作为列名。

$saa = "UPDATE  aspirantdt SET vote = vote + 1 where post_id = '$id' ";

或者使用反引号

$saa = "UPDATE  `aspirantdt` SET `vote` = `vote` + 1 where `post_id` = '$id' ";

答案 2 :(得分:1)

$saa = "update aspirantdt set vote = 'vote'+1 where 'post_id' = '$id' ";

表示'vote''post_id'文字字符串,而非表名(即,它会将$id与实际字符串{{1}进行比较而不是post_id列的值)。

你想要的是反引号来引用它们作为列/表名称;

post_id

答案 3 :(得分:0)

vote周围不需要引号作为列名,而不是字符串。

您的SQL可能正在尝试将vote1放入int列。