为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 sql 行中已提供的值中添加新值

如何在 sql 行中已提供的值中添加新值

PHP
白衣染霜花 2022-09-12 12:59:44
我希望代码能够正常工作,以便当用户赚取金额时应将其添加到表中,例如,添加后应包含用户金额+ 赚取Paid我的代码当前在每个声明上添加一个新行,但如果表中已有 a,我希望更新用户的余额。address示例:用户余额为 15.2,他们赚取了 2.3,此余额应更新为 17.5$address = trim($_POST["address"]);$q = $sql->prepare("INSERT INTO ".$dbtable_prefix."Paid                    SET                        `address` = ?,                        `amount` = ?                        ;");$claimlog_reward = $reward;if ($reward<1) {    $claimlog_reward = number_format($reward, 8, '.', '');}$q->execute(array(trim($_POST['address']), $claimlog_reward));
查看完整描述

1 回答

?
qq_花开花谢_0

TA贡献1835条经验 获得超7个赞

我将假设MySQL / MariaDB - 添加更新(前提是您的地址是主键)ON DUPLICATE KEY


$address = trim($_POST["address"]);

$claimlog_reward = $reward;

if ($reward<1) {

  $claimlog_reward = number_format($reward, 8, '.', '');

}


$q = $sql->prepare("INSERT INTO ".$dbtable_prefix."Paid

SET `address` = :address, `amount` = :amount

ON DUPLICATE KEY UPDATE amount = amount + :amount");

$q->bindValue(':address', trim($_POST['address']));

$q->bindValue(':amount', $claimlog_reward);

$q->execute();


查看完整回答
反对 回复 2022-09-12
  • 1 回答
  • 0 关注
  • 83 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信