SA-MP Forums Archive
MY SQL dosen't save data - 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: MY SQL dosen't save data (/showthread.php?tid=596220)



MY SQL dosen't save data - malackov - 14.12.2015

So hello, i started using mysql and made a simple login/register system the problem is when the player registers gets 20k money, 1score and when he leaves it dosen't save. but when i edit the player in mysql database and give him 20k go to a shop and lose 2 dollars it saves.

my register code:
PHP код:
if(dialogid==DIALOG_REGISTER)
    {
        if(
response)
        {
            new 
name[MAX_PLAYER_NAME],query[128],passwort[35];
            
GetPlayerName(playerid,name,sizeof(name));
            if(
strlen(inputtext)>3)
            {
                
mysql_escape_string(inputtext,passwort,dbhandle);
                
format(query,sizeof(query),"INSERT INTO user (username,password) VALUES ('%s',MD5('%s')) ",name,passwort);
                
mysql_function_query(dbhandle,query,false,"","");
                
TogglePlayerSpectating(playeridfalse);
                
SetSpawnInfo(playerid0240405.7584,-1540.9410,32.2734,230.52440,0,0,0,0,0);
                
SpawnPlayer(playerid);
                
SetPlayerMoney(playerid20000);
                
SetPlayerScore(playerid1);
                
pInfo[playerid][logged] = 1;
            } 
my save player function and onplayerdisconnect
PHP код:
savePlayer(playerid)
{
    if(
pInfo[playerid][logged]==0)return 1;
    
//Speichern level,money
    
new query[128];
    
format(query,sizeof(query),"UPDATE user SET level='%i',money='%i' WHERE id='%i'",pInfo[playerid][level],GetPlayerMoney(playerid),pInfo[playerid][id]);
    
mysql_function_query(dbhandle,query,false,"","");
    return 
1;
}
resetPlayer(playerid)
{
    
pInfo[playerid][level]=0;
    
pInfo[playerid][logged]=0;
    
pInfo[playerid][id]=0;
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
savePlayer(playerid);
    
resetPlayer(playerid);
    return 
1;




Re: MY SQL dosen't save data - malackov - 14.12.2015

nevermind, fixed it added a OnPlayerRegister callback to put the player an unique id ( lock this )