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=624170)
mysql problem -
OpCodexo - 12.12.2016
So i was trying to do a login/register system with mysql, i'm using mysql version r33
so basically i was trying to make a stock to save player data, the code is correct but it's not updating on mysql,
here is the code of the stock
Код:
stock SavePlayerData(playerid)
{
new Query[1000],PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
PlayerInfo[playerid][Cash] = GetPlayerMoney(playerid);
GetPlayerPos(playerid, PlayerInfo[playerid][LastPosX], PlayerInfo[playerid][LastPosY], PlayerInfo[playerid][LastPosZ]);
GetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
GetPlayerArmour(playerid, PlayerInfo[playerid][Armour]);
mysql_format(MySQL, Query, sizeof(Query), "UPDATE `players` SET `NormalName` = '%s', `Password` = '%s', `Cash` = '%d', `BankMoney` = '%d', `LastPosX` = '%f', `LastPosY` ='%f',`LastPosZ` = '%f',`Health` = '%f',`Armour` = '%f' WHERE `NormalName` = '%f' LIMIT 1",
PlayerName,
RetrievePassword(playerid),
PlayerInfo[playerid][Cash],
PlayerInfo[playerid][BankMoney],
PlayerInfo[playerid][LastPosX],
PlayerInfo[playerid][LastPosY],
PlayerInfo[playerid][LastPosZ],
PlayerInfo[playerid][Health],
PlayerInfo[playerid][Armour],
PlayerName);
mysql_query(MySQL, Query);
}
In the mysql debug, there is no errors too
Код:
[02:03:48] [DEBUG] mysql_format - connection: 1, len: 1000, format: "UPDATE `players` SET `NormalName` = '%s', `Password` = '%s', `Cash` = '%d', `BankMoney` = '%d', `LastPosX` = '%f', `LastPosY` ='..."
[02:03:49] [DEBUG] mysql_query - connection: 1, query: "UPDATE `players` SET `NormalName` = 'Alexander_Cooper', `Passwor"
[02:03:49] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[02:03:49] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[02:03:49] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[02:03:49] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[02:03:49] [DEBUG] CMySQLHandle::SaveActiveResult - cache saved with ID = 2
[02:03:49] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
Thanks in advance.
Re: mysql problem -
Abagail - 12.12.2016
%f is a float value, not a string. Change %f to %e at the end of the mysql_format(NormalName).
Re: mysql problem -
OpCodexo - 12.12.2016
That still doesn't fix the problem.
Re: mysql problem -
Abagail - 12.12.2016
Place print(Query) after the mysql_query function and post what shows up in the server log.
Re: mysql problem -
Runn3R - 12.12.2016
You really shouldn't save your data by the players name. Use row id/sqlid with the auto_increment value.
And by the way you are saving the password and the players name for no reason and you didn't escape the players name.