以 mysql/php 为单位的字段默认值递增


Increment of field default value in mysql/php

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

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

您在

update查询中有一个 sintax 错误,您使用的是 quotest 而不是反引号。对列名使用反引号,对值使用引号,尝试更改如下

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

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

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

或带反引号

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

表示 'vote''post_id'文本字符串,而不是表名(也就是说,它将$id与实际字符串post_id进行比较,而不是post_id列的值(。

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

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

vote不需要引号,因为它是列名,而不是字符串。

您的 SQL 可能试图将vote1放在 int 列中。