Increment value on MySQLi Update

后端 未结 1 339
南旧
南旧 2021-01-21 07:22

Simply trying to add points to an existing value in a column named \'Points\'. I\'ve read a few articles that suggest the beneath, but it\'s not working for me. Perhaps because

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 07:35

    If your column name starts with a number, you have to quote it in backticks:

    $query = "UPDATE users SET Points=Points+3 WHERE `1A`=$m1A";
    

    and:

    $query1 = "UPDATE rounds SET `1A` = 1";
    

    And I would recommend using a prepared statement with bound parameters to avoid sql injection problems.

    Edit: If your 1A column is not an integer column and the values are strings, you need to quote them.

    $query = "UPDATE users SET Points=Points+3 WHERE `1A`='$m1A'";
                                                          ^    ^
    

    Although that problem would be solved automatically with a prepared statement...

    0 讨论(0)
提交回复
热议问题