SA-MP Forums Archive
MySQL problem - 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: MySQL problem (/showthread.php?tid=625493)



MySQL problem - Ripster - 02.01.2017

I have two strings. I'm formating:
Код:
new bankszamla[11], bankjelszo[5];
format(bankszamla, 11, "%d%d%d-%d%d%d-%d%d%d",random(9),random(9),random(9),random(9),random(9),random(9),random(9),random(9),random(9));
format(bankjelszo, 5, "%d%d%d%d%d",random(9),random(9),random(9),random(9),random(9));
For some reason they're not saved to the database, only the player's ID.


What's the problem?
Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `Level`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`, `Eletkor`, `Nem`, `Skin`, `Szarmazas`, `Health`, `Armor`, `BankEgyenleg`, `BankSzamla`, `BankJelszo`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f, %d, %d, %d, %d, 100.0, 0.0, 0, '%e', '%e')",
playername, Player[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, Player[playerid][Adat][0], Player[playerid][Adat][1], Player[playerid][Adat][2], Player[playerid][Adat][3], bankszamla, bankjelszo);
mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);



Re: MySQL problem - Vince - 02.01.2017

Strings need a null terminator else you will run into all sorts of problems. Means the sizes of your strings need to be at least 12 and 6 chars long, respectively. Also use sizeof instead of inserting the size literally. Sizeof is an operator, not a function, and has no impact on performance. Furthermore, instead of calling random(9) over and over again you can just do this:

PHP код:
format(bankszamlasizeof(bankszamla), "%03d-%03d-%03d"random(1000), random(1000), random(1000)); 
PHP код:
format(bankjelszosizeof(bankjelszo), "%05d"random(100000)); 



Re: MySQL problem - Ripster - 02.01.2017

thx, it works!