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



problem saving mysql - jcvag44800 - 07.05.2014

Hello,

I'm turning my script into SQL.
But I have a problem.

When I finish the tutorial for present my server, I have the Tutorial variable set as 1.
When I disconnect, the variable is set to 1 on phpmyadmin.

But, when i'm reconnect, this is turn to 0 ...
There is the Debug log

Код:
[21:54:05] >> mysql_fetch_field_row( Connection handle: 1 )

[21:54:05] CMySQLHandler::FetchField("Tutorial") -
And the line who take the value:

OnPlayerUpdateSQL:

Код:
MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Tutorial", PlayerInfo[playerid][pTut]);

public MySQLUpdatePlayerInt(query[], sqlplayerid, sqlvalname[], sqlupdateint) // by Luk0r
{
	MySQLUpdateBuild(query, sqlplayerid);
	new updval[64];
	format(updval, sizeof(updval), "%s=%d", sqlvalname, sqlupdateint);
	strcat(query, updval, MAX_STRING);
	return 1;
}
Код:
	MySQLCheckConnection();
	new tmp2[256];
    new string2[64];
	new playername2[MAX_PLAYER_NAME];
	new playernamesplit[3][MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));
	split(playername2, playernamesplit, '_');
	MySQLFetchAcctSingle(PlayerInfo[playerid][pSQLID], "Password", PlayerInfo[playerid][pKey]);
	format(tmp2, sizeof(tmp2), "SELECT * FROM players WHERE id = %d LIMIT 1", PlayerInfo[playerid][pSQLID]);
	mysql_query(tmp2);
	mysql_store_result();
	if(strcmp(PlayerInfo[playerid][pKey],password, true ) == 0 )
	{
         ..
           mysql_get_field("Tutorial",Field); PlayerInfo[playerid][pTut] = strval(Field);
         ..
I don't know why...

Regards


Re: problem saving mysql - GutierrezDeVelasco - 07.05.2014

The error is obviously on getting the data from the database when you login so you need to make several tests check your mysql_log.txt you should get something like this
"Passing query SELECT * FROM `your table` WHERE `userName` = 'the user name' | ii"


Re : problem saving mysql - jcvag44800 - 07.05.2014

Negative. I don't get this error =(


Re: problem saving mysql - GutierrezDeVelasco - 07.05.2014

its not a error its what you should get in your mysql_log.txt file and that means your program is not reading format(tmp2, sizeof(tmp2), "SELECT * FROM players WHERE id = %d LIMIT 1", PlayerInfo[playerid][pSQLID]);

in what method do you have that and btw %d is for integers you want string so change it to %s


Re : problem saving mysql - jcvag44800 - 07.05.2014

Now, I'm doing this:
Код:
            new tmp;
	    mysql_query("SELECT PlayerLevel FROM players LIMIT 1");
	    mysql_store_result(); tmp = mysql_fetch_int();
	    PlayerInfo[playerid][pLevel] = tmp; mysql_free_result();
And it's work.


Re: problem saving mysql - GutierrezDeVelasco - 07.05.2014

by parts?
first the level, then the skin, etc, etc?
I recommend you to load every thing with one

new pName[24];
new query[256];
GetPlayerName(playerid, pName, 24);
format(query, sizeof(query), "SELECT * FROM `YOUR-TABLE` WHERE `userName` = '%s'", pName);
mysql_function_query(dbhandle, query, true, "OnQueryFinish", "ii", 1, playerid);