Add value to SQL table instead of replacing

Asked

Viewed 169 times

3

Using the following code:

UPDATE `login` SET diasvip = '".+$_POST["qntvip"]."' WHERE userid = '".$_POST["userid"]."'

When I execute, it replaces the diasvip by the value posted instead of adding the value posted to those already existing in the table. How do I sum operation?

1 answer

6


If you want to add to what already exists you must do this account, so:

"UPDATE `login` SET diasvip = diasvip + " . $_POST["qntvip"] . " WHERE userid = '".$_POST["userid"] . "'"

I put in the Github for future reference.

Note that you are riding a string then the plus sign should already be inside the text, what you put outside the text is just what varies.

And you should not put apostrophe on all data, only when it is characters, in the case of the amount that is a number, should not have.

Note that this form is extremely insecure, I would reverse it to not suffer SQL Injection.

  • Perfect that same ;) Thank you.

  • I forgot sorry rsrs. Reply marked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.