2012-01-17 53 views
0

我有一个名为submission的MySQL数据库表,其中有一个名为points的字段,其类型为bigint(100)将变量的值添加到数据库字段

在一个PHP文件中,我有一个变量,其数值为$commentpoints

在PHP文件中,我怎样才能将$commentpoints添加到points

回答

3

它在你的SQL更新查询其添加的问题:

$sql = 'UPDATE submissions 
    SET points = points + ' . (int) $commentpoints . ' 
    WHERE id = ' . (int) $id; 

这将增加$commentpoints在数据库中的点值;只要确保使用where子句,以便不将其添加到提交表中的每个记录。

0
UPDATE table SET points = '[your value]' 
0
mysql_query("UPDATE submission SET points = '$commentpoints'"); 
0
$sql = "UPDATE submission 
     SET points = points + ? 
      WHERE commentid=?"; 
$q = $conn->prepare($sql); 
$q->execute(array($commentpoints,$commentid));