-1

Can someone tell me how I can add value to database?

My code looks like this:

        if(isset($_GET['gold']))//
      {
        $gold = $_GET['gold'];
        mysqli_query($db_handle, "UPDATE serverplayers SET Gold='$gold' WHERE Unique_Id = '$unique_id'");
      }
    }
  mysqli_close($db_handle);
}

In this code I'm set new value "gold" at table "gold" . But I don't want do that . I want add value (+) to current value in "gold" table.

Note:"$gold" is my variable , "gold" is my table.

Thanks for any advice. Best Regards Piter.

3

2 Answers 2

0

This method is way too vulnerable to sql injection, you should at least check if $_GET['gold'] is a number and isn't equal to 0.

If you want to add number to existing column in mysql you should do something like:

mysqli_query($db_handle, "UPDATE serverplayers SET Gold=(ifnull(Gold, 0) + ".$gold.") WHERE Unique_Id = '".$unique_id . "'");

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

2 Comments

Thanks you very much ! / Dziękuje za pomoc! :)
Nie ma problemu, powodzenia :)
0

Update your query like this:

"UPDATE serverplayers SET Gold='".$gold."' WHERE Unique_Id = '".$unique_id."'";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.