user3215045
user3215045

Reputation: 75

how can i update my table column with php mysql using increments

i am creating a page that has a verification function when an order is succesful

i am trying to increase the value of a column incrementally using a variable

but i keep get an error

Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '+ '57' WHERE Username = 'kokoman'' at line 2

This what i am working with for the increment

$sql = "UPDATE users
           SET package = '$packagex', diamonds + $diamondx, rate = '$ratx', amount + $amountx
         WHERE  Username = '$usernamex'";

That keeps generating the above error

i am using that because i know if i need to increase the value of a column

i would just use "set column +1"

but now i am trying to use a variable because it has to be dynamic but i get the error

please help tanks

Upvotes: 1

Views: 41

Answers (2)

Daniyal Nasir
Daniyal Nasir

Reputation: 707

From my understanding you want add value to previously held values of columns amount and diamondsfor that, Try this:

$amountx = 1;
$diamondx = 1;
$sql = "UPDATE users
        SET package = '$packagex',
            diamonds =  diamonds  + $diamondx,
            rate = '$ratx',
            amount = amount + $amountx
        WHERE  Username = '$usernamex'";

Upvotes: 0

Barmar
Barmar

Reputation: 780984

The SET clause needs to contain assignments. diamonds + $diamondx should be diamonds = diamonds + $diamondx, and similarly for the other columns.

You should also stop substituting variables into queries and learn to use prepared statements with parameters.

Upvotes: 1

Related Questions