Raised This Month: $32 Target: $400
 8% 

[MYSQL] Load/Save won't work properly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
quilhos
Veteran Member
Join Date: Jun 2010
Old 12-10-2014 , 14:01   [MYSQL] Load/Save won't work properly
Reply With Quote #1

Load/save seems to be working poorly and not saving all the data that is supposed to store.
Load
PHP Code:
public Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    new 
Data[1]
    
Data[0] = id
    
    
//we will now select from the table `tutorial` where the steamid match
    
formatszTempcharsmaxszTemp ),"SELECT `rating`, `kills`, `deaths` FROM `%s` WHERE `authid` = '%s'"SQL_TABLEszSteamId )
        
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1
    {
        
//.if there are no results found
        
        
new szSteamId[32]
        
get_user_authid(idszSteamIdcharsmax(szSteamId)) // get user's steamid
        
        //  if its still pending we can't do anything with it
        
if (equal(szSteamId,"ID_PENDING"))
            return 
PLUGIN_HANDLED
            
        
new szTemp[512]
        
        
// now we will insturt the values into our table.
        
formatszTempcharsmaxszTemp ), "INSERT INTO %s ( `authid`, `nick`, `rating`, `kills`, `deaths`) VALUES( '%s', '%s', '%i', '%i', '%i' )"SQL_TABLEszSteamIdg_szNameid ],elo_ratingid ],g_iKillsid ],g_iDeathsid ] )
            
        
SQL_ThreadQueryg_SqlTuple"IgnoreHandle"szTemp )
    } 
        
    else
    {
        
elo_ratingid ] = SQL_ReadResultQuery)
            
        
g_iKillsid ] = SQL_ReadResultQuery)
        
g_iDeathsid ] = SQL_ReadResultQuery)
    }
    
    return 
PLUGIN_HANDLED

Save
PHP Code:
public Save_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    
// Here we will update the user hes information in the database where the steamid matches.
    
formatexszTempcharsmaxszTemp ),"UPDATE %s SET nick = '%s', rating = '%i', kills = '%i', deaths = '%i' WHERE authid = '%s'",SQL_TABLEg_szNameid ], elo_ratingid ], g_iKillsid ], g_iDeathsid ], szSteamIdid ] )
    
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED

__________________
ELO RATING SYSTEM - SQL [COMPLETE]
Quote:
Originally Posted by Liverwiz View Post
DDDRRRRAAAAMMMMAAAAA!!!???

Put this shit on pause while i go get some popcorn!!
quilhos is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 12-11-2014 , 06:48   Re: [MYSQL] Load/Save won't work properly
Reply With Quote #2

On Save
Code:
formatex( szTemp, charsmax( szTemp ),"UPDATE %s SET nick = '%s', rating = '%i', kills = '%i', deaths = '%i' WHERE authid = '%s'",SQL_TABLE, g_szName[ id ], elo_rating[ id ], g_iKills[ id ], g_iDeaths[ id ], szSteamId[ id ] )
->
Code:
formatex( szTemp, charsmax( szTemp ),"UPDATE %s SET nick = '%s', rating = '%i', kills = '%i', deaths = '%i' WHERE authid = '%s'",SQL_TABLE, g_szName[ id ], elo_rating[ id ], g_iKills[ id ], g_iDeaths[ id ], szSteamId )
__________________
Kia is offline
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 12-19-2014 , 10:28   Re: [MYSQL] Load/Save won't work properly
Reply With Quote #3

Try to save the points when the player kill another or die, dont save on player disconnect, and regist the client if they are new on the server only when they get any points.
Dont forget to turn into 0 all the stats on client_authorized and load points after that
__________________
skz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-20-2014 , 12:26   Re: [MYSQL] Load/Save won't work properly
Reply With Quote #4

Kia found what is likely causing the issue which is resulting in only a piece, if any, of the users steamid to be passed to the SQL query.

@quilhos, you may want to store the users steamid in a global variable since this will never change in-game, and read the players name when you need it as this can change at any time. You appear to be doing the opposite.
__________________

Last edited by Bugsy; 12-20-2014 at 12:27.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode