Help with UPDATE mysql
#1

hello, I would have a problem, I would like to understand why when I save the ammo with the weapon that is already present in MYSQL, instead of modifying the number of ammunition I create another string with the weapon + the additional ammunition.

Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO weapon_house VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE `Ammo` = `Ammo`+'%d'", PlayerInfo[playerid][ID], weapon, inputtext[0], inputtext[0]);
mysql_tquery(mysql, query);
Thanks to those who lose time for me <3
Reply
#2

if i read it right i think your problem is with your keys and sql table anyway just in case :
your player sql id and weapon id needs to be unique in case of using this style
Код:
Ref Mysql Learning pdg >>>

If you specify an ON DUPLICATE KEY UPDATE clause and a row to be inserted would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row occurs. For example, if column a is declared as UNIQUE and contains the value 1, the following two statements have similar effect:
INSERT INTO t1 (a,b,c) VALUES (1,2,3)
  ON DUPLICATE KEY UPDATE c=c+1;

UPDATE t1 SET c=c+1 WHERE a=1;
Код:
/*
(The effects are not identical for an InnoDB table where a is an auto-increment column. With an auto-increment column, an INSERT statement increases the auto-increment value but UPDATE does not.)

*/
Код HTML:
UNIQUE KEY `weaponid`
so just try checking the weaponid too if its uniqe or prm so if its not make it then and if it is and player sqlid is too then try to
insert and update in different functions
Reply
#3

sorry, can you explain to me with the string I used that I did not understand so much?
Reply
#4

Quote:
Originally Posted by DarkWorldJack
Посмотреть сообщение
sorry, can you explain to me with the string I used that I did not understand so much?
not with your code your table you have to set player id weapon id to be unique
Reply
#5

thanks, Resolved <3
Reply
#6

Quote:
Originally Posted by DarkWorldJack
Посмотреть сообщение
thanks, Resolved <3
your welcome
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)