MySQL Saving [Not Working]
#1

Код:
new query[518];

mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET Admin=%d, Money=%d, posX=%f, posY=%f, posZ=%f WHERE ID=%d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query);
The above code is what I used to save my character. It's not working, it just sets everything in the database to 0. Anyone know why?
Reply
#2

do an fprint with the query and show me the results
Reply
#3

Код:
[13:41:55] [DEBUG] mysql_format - connection: 1, len: 512, format: "SELECT * FROM `users` WHERE `Username` = '%e' LIMIT 1"
[13:41:55] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `users` WHERE `Username` = 'William_Nickson' LIMIT", callback: "SaveCharacter", format: "i"
[13:41:55] [DEBUG] CMySQLQuery::Execute[SaveCharacter] - starting query execution
[13:41:55] [DEBUG] CMySQLQuery::Execute[SaveCharacter] - query was successfully executed within 0.620 milliseconds
[13:41:55] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[13:41:55] [DEBUG] Calling callback "SaveCharacter"..
[13:41:55] [DEBUG] mysql_format - connection: 1, len: 518, format: "UPDATE `users` SET Admin=%d, Money=%d, posX=%f, posY=%f, posZ=%f WHERE ID=%d"
[13:41:55] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `users` SET Admin=0, Money=0, posX=0.0, posY=0.0, posZ=0.", callback: "(null)", format: "(null)"
[13:41:55] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[13:41:55] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[13:41:55] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 22.321 milliseconds
[13:41:55] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
fprint returned this:

Код:
UPDATE `users` SET Admin=0, Money=0, posX=0.0, posY=0.0, posZ=0.0 WHERE ID=25
Reply
#4

Hello!

Can we look the code of the whole OnPlayerDisconnect-Callback or where you save the player?
Reply
#5

Are you sure that you do not reset the variables in OnPlayerDisconnect and then trying to save? It has to be vice versa.
Reply
#6

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

Can we look the code of the whole OnPlayerDisconnect-Callback or where you save the player?
Код:
PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
//Save
new query[518];
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET Admin=%d, Money=%d, posX=%f, posY=%f, posZ=%f WHERE ID=%d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query);
printf(query);
That's it, the rest is the same as above. Just saving every variable, string and float. It all returns 0 though.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Are you sure that you do not reset the variables in OnPlayerDisconnect and then trying to save? It has to be vice versa.
OnPlayerDisconnect:

Код:
new query[512];
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `users` WHERE `Username` = '%e' LIMIT 1", RPNU(playerid));
mysql_tquery(mysql, query, "SaveCharacter", "i", playerid);
SaveCharacter:
Код:
forward SaveCharacter(playerid);
public SaveCharacter(playerid)
{
	//Load
	PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
	PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
	GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
	//Save
	new query[518];
	mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET Admin=%d, Money=%d, posX=%f, posY=%f, posZ=%f WHERE ID=%d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ], PlayerInfo[playerid][ID]);
        mysql_tquery(mysql, query);
        printf(query);
}
Reply
#8

What's the point of selecting everything from database and until the query is executed, the player has already disconnected and GetPlayerPos should return false; hence the coordinates are 0.0

In OnPlayerDisconnect, save directly:
pawn Код:
GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
new query[518];
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET Admin=%d, Money=%d, posX=%f, posY=%f, posZ=%f WHERE ID=%d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query);
printf(query);
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
What's the point of selecting everything from database and until the query is executed, the player has already disconnected and GetPlayerPos should return false; hence the coordinates are 0.0

In OnPlayerDisconnect, save directly:
pawn Код:
GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
new query[518];
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET Admin=%d, Money=%d, posX=%f, posY=%f, posZ=%f WHERE ID=%d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query);
printf(query);
Thank you, it's working now.
Reply


Forum Jump:


Users browsing this thread: