0

I have database with column "kredit". I want to add $dobitak to kredit.

So if is in database kredit=10, and $dobitak=15 kredit+dobitak=25 but my code return me kredit=15 in database.

$sql = "UPDATE user
    SET  kredit='kredit' + '".$dobitak."'
    WHERE id='" . $info['user_id'] . "'";

What I need to change to get correct result in database?

2
  • Use back ticks or remove the single quotes,you are adding a string. Commented Jan 4, 2014 at 12:07
  • 3
    Remove single quotes arround the column SET kredit=kredit + '".$dobitak."' Commented Jan 4, 2014 at 12:08

2 Answers 2

3

try this ...

$sql = "UPDATE user
    SET  kredit=kredit + ".$dobitak."
    WHERE id='" . $info['user_id'] . "'";

Because for integer type field you need not enclose with "'"

Sign up to request clarification or add additional context in comments.

1 Comment

If you want appreciate then choose this as correct answer... :)
0
kredit = kredit + '". $dobitak ."'
WHERE id='" . $info['user_id'] . "'";

Remove the ' ' from around kredit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.