Trevor Ackermann Trevor Ackermann - 2 months ago 5x
MySQL Question

PHP form to update MYSQL Row

I have a PHP form that updates a MySQL database. I want to add credits to the current credits in the row. Basic math

Current Credits 50 add another 50 credits = 100

This is my current string (EDITED)

$sql = sprintf("UPDATE h_clients ". "SET credits = $credits + '%s'" . "WHERE id = $id",

Currently this works but it doesn't add the new credits with the current credits in DB

Here is the full code:

$sql = sprintf("UPDATE h_clients ". "SET credits = $credits + '%s'" . "WHERE id = $id",


if (mysql_query($sql, $con)) {
$insertSuccessful = true;
} else {
echo $sql;
echo "\n" . mysql_error($con);
echo "mysql err no : " . mysql_errno($con);


return $insertSuccessful;


Seems you have wrong column name in assign credits

"UPDATE h_clients SET credits = credits +  $credits  WHERE id = $id",