MySQL update
#1

Hello guys my updating table is not working
Here is my code:
Here is the OnPlayerDisconnect callback:
PHP код:
mysql_format(zMySQLstringsizeof(string), "SELECT * FROM `accounts` WHERE Username = '%e'"PlayerName(playerid));
mysql_tquery(zMySQLstring"SavePlayersData""d"playerid); 
Here is my SavePlayersData callback:
PHP код:
forward SavePlayersData(playerid);
public 
SavePlayersData(playerid)
{
    new 
query2[2048];
    
mysql_format(zMySQLquery2sizeof(query2), "UPDATE `accounts` SET `Money` = '%d', `Faction` = '%d', `Rank` = '%d', `Admin` = '%d', `VIP` = '%d', `Marijuana` = '%d', `Cocaine` = '%d', `Heroine` = '%d', `Amphetamine` = '%d', `Extasae` = '%d', `Spawn` = '%d', `aDuty` = '%d', `aList` = '%d', `Language` = '%d' WHERE `Username` = '%e'",
    
PlayerInfo[playerid][Money], PlayerInfo[playerid][Faction], PlayerInfo[playerid][Rank], PlayerInfo[playerid][Admin], PlayerInfo[playerid][VIP], PlayerInfo[playerid][Marijuana], PlayerInfo[playerid][Cocaine], PlayerInfo[playerid][Heroine], PlayerInfo[playerid][Amphetamine], PlayerInfo[playerid][Extasae], PlayerInfo[playerid][Spawn], PlayerInfo[playerid][aDuty], PlayerInfo[playerid][aList], PlayerInfo[playerid][Language], PlayerName(playerid));
    
mysql_query(zMySQLquery2);
    return 
1;

Reply
#2

Few things:
- I doubt you need 2048 cells; the string isn't that long.
- You should use threaded queries, especially if you save with this often. Use mysql_tquery(zMySQL, query2, "") instead and that's it.
- If you're saving by username, you're doing something wrong. Each account should have a unique ID (A.I/PRIMARY settings are good), which you use to reference for most database actions (them connecting being an exception, as you need to look it up that way).
- I don't get why you're selecting, only to save, when you don't even check if the account exists? (which you should know without as you should have some type of logged in and account ID reference stored).
- mysql_log.log in the server directory will show any MySQL errors, depending on if logging is enabled within the plugin.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)