SA-MP Forums Archive
SQL annoying me. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQL annoying me. (/showthread.php?tid=344937)



SQL annoying me. - iGetty - 23.05.2012

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?


Re: SQL annoying me. - Pizzy - 23.05.2012

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


Re: SQL annoying me. - Vince - 23.05.2012

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.


Re: SQL annoying me. - iGetty - 23.05.2012

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


Re: SQL annoying me. - Pizzy - 23.05.2012

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


Re: SQL annoying me. - ReneG - 23.05.2012

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]);



Re: SQL annoying me. - iGetty - 23.05.2012

Thanks!


Re: SQL annoying me. - Verbal - 23.05.2012

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