我有一个名为submission
的MySQL数据库表,其中有一个名为points
的字段,其类型为bigint(100)
。将变量的值添加到数据库字段
在一个PHP文件中,我有一个变量,其数值为$commentpoints
。
在PHP文件中,我怎样才能将$commentpoints
添加到points
?
我有一个名为submission
的MySQL数据库表,其中有一个名为points
的字段,其类型为bigint(100)
。将变量的值添加到数据库字段
在一个PHP文件中,我有一个变量,其数值为$commentpoints
。
在PHP文件中,我怎样才能将$commentpoints
添加到points
?
它在你的SQL更新查询其添加的问题:
$sql = 'UPDATE submissions
SET points = points + ' . (int) $commentpoints . '
WHERE id = ' . (int) $id;
这将增加$commentpoints
在数据库中的点值;只要确保使用where子句,以便不将其添加到提交表中的每个记录。
UPDATE table SET points = '[your value]'
mysql_query("UPDATE submission SET points = '$commentpoints'");
$sql = "UPDATE submission
SET points = points + ?
WHERE commentid=?";
$q = $conn->prepare($sql);
$q->execute(array($commentpoints,$commentid));