duandianzhong8315
2012-01-17 23:54
浏览 31
已采纳

将变量的值添加到数据库字段

I have a MySQL database table called submission with a field called points with a type of bigint(100).

On a PHP file, I have a variable called $commentpoints with a numerical value.

In the PHP file, how could I add $commentpoints to points?

图片转代码服务由CSDN问答提供 功能建议

我有一个名为 submission 的MySQL数据库表,其中包含一个名为 points <的字段 / code>,类型为 bigint(100)

在PHP文件中,我有一个名为 $ commentpoints 的变量,带有数值。

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • douhengdao4499 2012-01-17 23:59
    已采纳

    It's a matter of adding it in your SQL update query:

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

    That will add the value of $commentpoints to the points in the database; just make sure to use the where clause so you don't add it to every record in the submissions table.

    点赞 评论
  • douhu2898 2012-01-17 23:57
    UPDATE table SET points = '[your value]'
    
    点赞 评论
  • drbmhd9583 2012-01-18 00:00
    mysql_query("UPDATE submission SET points = '$commentpoints'");
    
    点赞 评论
  • dpxyfa4718 2012-01-18 00:01
    $sql = "UPDATE submission
            SET points = points + ?
                WHERE commentid=?";
    $q = $conn->prepare($sql);
    $q->execute(array($commentpoints,$commentid)); 
    
    点赞 评论

相关推荐 更多相似问题