2012-01-17 60 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));