Hey Guys i just was asking if i had data called zf and table cq_user and there is coulmn called emoney and i wanna increase This emoney Value By sumbit Like Increase at php page...

but i need This emoneyvalue if it's 100 i need to increase it by 10 so it's will be 110...

i dont want all id's being same emoney value but same emoney increase value and Thanks all and iam waiting for any solve and Thanks

Dani AI

Generated

As asked, you want to add a fixed amount to a single user’s emoney rather than overwrite every row. pointed out a direct UPDATE — that works, but without a WHERE clause it changes every row. Use a WHERE to target the user, validate inputs, and use a prepared statement to avoid injection. If multiple requests can happen at the same time, either (a) do the increment in one server-side statement so it is atomic, or (b) lock the row in a transaction, read the current value, compute the new value, then write it.

Example using PDO with a row lock (safe for InnoDB):

$pdo->beginTransaction();

$stmt = $pdo->prepare('SELECT emoney FROM cq_user WHERE id = ? FOR UPDATE');
$stmt->execute([$id]);
$current = $stmt->fetchColumn();

if ($current === false) {
    $pdo->rollBack();
    // handle missing user
}

$new = (int)$current + (int)$delta;

$upd = $pdo->prepare('UPDATE cq_user SET emoney = ? WHERE id = ?');
$upd->execute([$new, $id]);

$pdo->commit();

Notes and cautions:

  • Always validate/cast $id and $delta as integers and check for negative or overflow values.
  • SELECT ... FOR UPDATE requires InnoDB; MyISAM does not support row-level locking.
  • For high concurrency, prefer a single atomic UPDATE on the server (it avoids the select/update round trip).
  • Log every change in a separate transactions/audit table (user_id, delta, old_value, new_value, timestamp, reason) so you can trace adjustments.
  • Check rowCount() or affected rows to confirm the update succeeded and handle errors with try/catch and rollbacks.

Recommended Answers

All 2 Replies

So Guys any advice?!

try this: update cq_user set emoney = emoney + 10

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.