0

I wish to update a field in my database, to the current value, plus another value.

For some reason, below code doesn't work - although I don't receive any PHP error:

$stmt = $dbh->prepare("UPDATE users SET rbalance=rbalance+':amount', alertpay_invest=alertpay_invest+':amount' WHERE id=':userid'"); //Works
                    $stmt->bindParam(':amount', $amount);
                    $stmt->bindParam(':userid', $itemType[0]);
                    $stmt->execute();

Can someone please help me?

I am new to PDO, and I don't know how to enable error debugging either..

oliverbj
  • 5,771
  • 27
  • 83
  • 178

1 Answers1

1

replace this

  rbalance=rbalance+':amount'

by

 rbalance=rbalance+ :amount

you are adding int with string

and this

   alertpay_invest=alertpay_invest+':amount'

to

  alertpay_invest=alertpay_invest+ :amount

whole query:

 UPDATE users SET rbalance=rbalance+ :amount , 
                  alertpay_invest=alertpay_invest+ :amount  
 WHERE id= :userid 
echo_Me
  • 37,078
  • 5
  • 58
  • 78