SQL annoying me.
#1

Hello, I've got my SQL system, but it seems to save the wrong information in the wrong column on the SQL database...

I have:

pawn Код:
stock SaveStats(playerid)
{
    new pname[24];
    GetPlayerName(playerid,pname,24);
    format(SQL_Query,sizeof(SQL_Query),"UPDATE `Accounts` SET `Money` = '%i', `Level` = '%i', `AdminLevel` = '%i', `Faction` = '%i', `FactionRank` = '%i', `RegistrationStep` = '%i', `BirthDay` = '%i', `BirthMonth` = '%i', `BirthYear` = '%i', `SpawnPoint` = '%i', `TutorialComplete` = '%i' WHERE `Username` = '%s'",
    Player[playerid][Money],
    Player[playerid][Level],
    Player[playerid][AdminLevel],
    Player[playerid][Faction],
    Player[playerid][FactionRank],
    Player[playerid][RegistrationStep],
    Player[playerid][BirthDay],
    Player[playerid][BirthMonth],
    Player[playerid][BirthYear],
    Player[playerid][SpawnPoint],
    Player[playerid][TutorialComplete],
    pname);

    mysql_query(SQL_Query);
    mysql_free_result();
    return 1;
}
It just doesn't save the right thing in the right place, what the hell can be wrong?
Reply
#2

Remove mysql_free_result();, as you are not storing anything mysql / pointless and does nothing.

Download your mysql_log.txt from the server and open it up, and post whatever it shows about this query in this post.

If all else fails - Instead of %i, use %d
Reply
#3

As always, when problems with MySQL rise up: enable the debug right away (as suggested above). Also a good practice is to have OnQueryError in your script. Whenever an error pops up, you can forward it to the server window or send a message to ingame administrators.
Reply
#4

I've kind of fixed it, I started using mysql_fetch_field_row

Only thing is, how do I read a string like, say I have Player[playerid][Accent]

How do I load it? :P
Reply
#5

strmid(Player[playerid][Accent], loadedstring, 0, strlen(loadedstring), 20);
Reply
#6

The same way you load everything else. Then you would extract the field and store it into the accent string like so.
pawn Код:
mysql_fetch_field_row(field,"Accent");  
strmid(PlayerInfo[playerid][pAccent], field, 0, sizeof(field), sizeof(PlayerInfo[playerid][pAccent]);
Reply
#7

Thanks!
Reply
#8

Also, try and use strcat for the format. And don't use "mysql_free_result".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)