MYSQL Accounts won't save..
#1

Hello, i have recently converted my gamemode to MYSQL and i got no warnings/errors, but i have a big problem that accounts are not saving.. I will post every code i have here so you can maybe help me.

PHP код:
public OnGameModeInit()
{
    
mysql_log(ERROR WARNING);
    
    new 
MySQLOptoption_id mysql_init_options();
    
mysql_set_option(option_idAUTO_RECONNECTtrue);
    
Database mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_PASSMYSQL_DATABASEoption_id);
    if(
Database == MYSQL_INVALID_HANDLE || mysql_errno(Database) != 0)
    {
        print(
"SERVER: Untitled Deathmatch couldn't connect to the MySQL server, closing.");
        
SendRconCommand("exit");
        return 
1;
    }
    print(
"SERVER: Untitled Deathmatch has connected to the MySQL database."); 
PHP код:
public OnGameModeExit()
{
 foreach(new 
iPlayer)
    {
        if(
IsPlayerConnected(i))
        {
            
OnPlayerDisconnect(i1);
        }
    }
    
mysql_close(Database); 
PHP код:
public OnPlayerConnect(playerid)
{
   new 
DB_Query[115];
    
    
GetPlayerName(playeridPlayerInfo[playerid][pName], MAX_PLAYER_NAME);
    
Corrupt_Check[playerid]++;
    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "SELECT * FROM `PLAYERS` WHERE `USERNAME` = '%e' LIMIT 1"PlayerInfo[playerid][pName]);
    
mysql_tquery(DatabaseDB_Query"OnPlayerDataCheck""ii"playeridCorrupt_Check[playerid]); 
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
Corrupt_Check[playerid]++;
    new 
DB_Query[256];
    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `CASH` = %d, `KILLS` = %d, `DEATHS` = %d, `BAN` = %d, `ADMIN` = %d, `WARNINGS` = %d, `VIP` = %d, `TOKENS` = %d, `CHAT` = %d, `SKIN` = %d, `NAMECHANGES` = %d, `MODE` = %d, WHERE `ID` = %d LIMIT 1",
    
PlayerInfo[playerid][pScore], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pBan], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pWarnings], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pToken], PlayerInfo[playerid][pChat], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pNamechanges], PlayerInfo[playerid][pMODE], PlayerInfo[playerid][pID]);
    
mysql_tquery(DatabaseDB_Query);
    if(
cache_is_valid(PlayerInfo[playerid][Player_Cache]))
    {
        
cache_delete(PlayerInfo[playerid][Player_Cache]);
        
PlayerInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
    }
    
PlayerInfo[playerid][LoggedIn] = false;
    print(
"OnPlayerDisconnect has been called."); 
PHP код:
OnDialogResponse
{
   switch (
dialogid)
    {
        case 
DIALOG_LOGIN:
        {
            if(!
response) return Kick(playerid);
            new 
Salted_Key[65];
            
SHA256_PassHash(inputtextPlayerInfo[playerid][Salt], Salted_Key65);
            if(
strcmp(Salted_KeyPlayerInfo[playerid][pPassword]) == 0)
            {
                
cache_set_active(PlayerInfo[playerid][Player_Cache]);
                
cache_get_value_int(0"ID"PlayerInfo[playerid][pID]);
                
cache_get_value_int(0"KILLS"PlayerInfo[playerid][pKills]);
                
cache_get_value_int(0"DEATHS"PlayerInfo[playerid][pDeaths]);
                
cache_get_value_int(0"SCORE"PlayerInfo[playerid][pScore]);
                
cache_get_value_int(0"CASH"PlayerInfo[playerid][pCash]);
                
                
cache_get_value_int(0"BAN"PlayerInfo[playerid][pBan]);
                
cache_get_value_int(0"IP"PlayerInfo[playerid][pIP]);
                
SetPlayerScore(playeridPlayerInfo[playerid][pScore]);
                
ResetPlayerMoney(playerid);
                
GivePlayerMoney(playeridPlayerInfo[playerid][pCash]);
                
cache_delete(PlayerInfo[playerid][Player_Cache]);
                
PlayerInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
                
PlayerInfo[playerid][LoggedIn] = true;
                
                
PlayerInfo[playerid][pMODE] = NO_MODE;
                   
SetSpawnInfo(playerid0PlayerInfo[playerid][pSkin], 1729.2920, -1669.479422.6151 ,42.4700, -1, -1, -1, -1, -1, -1);
                   
SetPlayerInterior(playerid0);
                   
SetPlayerVirtualWorld(playerid400);
                
SpawnPlayer(playerid);
                
                
SendClientMessageEx(playerid, -1"SERVER: Welcome back %s"GetPlayerNameEx(playerid));
            }
            else
            {
                new 
String[150];
                
PlayerInfo[playerid][PasswordFails] += 1;
                
printf("%s has failed to log-in. (%d)"PlayerInfo[playerid][pName], PlayerInfo[playerid][PasswordFails]);
                if (
PlayerInfo[playerid][PasswordFails] >= 3)
                {
                    
format(Stringsizeof(String), "SERVER: %s has been kicked, reason: (%d/3) login fails."PlayerInfo[playerid][pName], PlayerInfo[playerid][PasswordFails]);
                    
SendClientMessageToAll(COLOR_LIGHTREDString);
                    
Kick(playerid);
                }
                else
                {
                    
format(Stringsizeof(String), "Wrong password, you have %d out of 3 tries."PlayerInfo[playerid][PasswordFails]);
                    
SendClientMessage(playeridCOLOR_LIGHTREDString);
                      
format(Stringsizeof(String), "{FFFFFF}Welcome back, {00CED1}%s. {FFFFFF}Please type your password below to login into the server."PlayerInfo[playerid][pName]);
                    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"Login"String"Login""Leave");
                }
            }
        }
        case 
DIALOG_REGISTER:
        {
            if(!
response) return Kick(playerid);
            if(
strlen(inputtext) <= || strlen(inputtext) > 60)
            {
                
SendClientMessage(playeridCOLOR_LIGHTRED"Invalid password length, should be 5 - 60.");
                new 
String[150];
                
format(Stringsizeof(String), "{FFFFFF}Welcome to Untitled Deathmatch, {00CED1}%s. {FFFFFF}Please input a password below to register."PlayerInfo[playerid][pName]);
                
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD"Register"String"Register""Leave");
            }
            else
            {
                for (new 
010i++)
                {
                    
PlayerInfo[playerid][Salt][i] = random(79) + 47;
                }
                
PlayerInfo[playerid][Salt][10] = 0;
                
SHA256_PassHash(inputtextPlayerInfo[playerid][Salt], PlayerInfo[playerid][pPassword], 65);
                new 
DB_Query[225];
                
mysql_format(DatabaseDB_Querysizeof(DB_Query), "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)\
                VALUES ('%e', '%s', '%e', '20', '0', '0', '0')"
PlayerInfo[playerid][pName], PlayerInfo[playerid][pPassword], PlayerInfo[playerid][Salt]);
                 
mysql_tquery(DatabaseDB_Query"OnPlayerRegister""d"playerid);
             } 
PHP код:
forward public OnPlayerDataCheck(playeridcorrupt_check);
public 
OnPlayerDataCheck(playeridcorrupt_check)
{
    if (
corrupt_check != Corrupt_Check[playerid]) return Kick(playerid);
    
    new 
String[150];
    if(
cache_num_rows() > 0)
    {
        
cache_get_value(0"PASSWORD"PlayerInfo[playerid][pPassword], 65);
        
cache_get_value(0"SALT"PlayerInfo[playerid][Salt], 11);
        
PlayerInfo[playerid][Player_Cache] = cache_save();
        
format(Stringsizeof(String), "{FFFFFF}Welcome back, {00CED1}%s. {FFFFFF}Please type your password below to login into the server."PlayerInfo[playerid][pName]);
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"Login"String"Login""Leave");
    }
    else
    {
        
format(Stringsizeof(String), "{FFFFFF}Welcome to Untitled Deathmatch, {00CED1}%s. {FFFFFF}Please input a password below to register."PlayerInfo[playerid][pName]);
        
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD"Register"String"Register""Leave");
    }
    return 
1;
}
forward public OnPlayerRegister(playerid);
public 
OnPlayerRegister(playerid)
{
    
TogglePlayerControllable(playeridfalse);
    
SendClientMessage(playeridCOLOR_WHITE"Welcome to Untitled Deathmatch.");
    
SetSpawnInfo(playerid0PlayerInfo[playerid][pSkin], 1729.2920, -1669.479422.6151 ,42.4700, -1, -1, -1, -1, -1, -1);
    
SetPlayerInterior(playerid0);
    
SetPlayerVirtualWorld(playerid400);
    
SpawnPlayer(playerid);
    
PlayerInfo[playerid][LoggedIn] = true;
    return 
1;

Sorry for the huge spam but i really need this fixed, i am tired of working on easy-mysql i don't even know the functions of that, i want to start using MYSQL.

BTW: When i log-in the register dialog shows, i type my password there and nothing happens, OnPlayerRegister doesn't get called.
Reply
#2

post your SQL logs please.
Reply
#3

Quote:
Originally Posted by Mugala
Посмотреть сообщение
post your SQL logs please.
There's no SQL logs, but the mysql has been connected to the server though
Reply
#4

Your DB_Query variable you use to send the update query is too short.
When you replace the %d with 1234567890 (which is 10 chars long and is the length of an integer as text), the query gets to 342 characters long, yours is only 256 chars long.
Even without replacing the %d with any value, your query is already 230 chars long.
You need to foresee this because players can have up to 2.1 billion dollars (32-bit integer), even score, bankaccount and other values might get that high.

Make it at least 350 chars long and try again.
Reply
#5

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
Your DB_Query variable you use to send the update query is too short.
When you replace the %d with 1234567890 (which is 10 chars long and is the length of an integer as text), the query gets to 342 characters long, yours is only 256 chars long.
Even without replacing the %d with any value, your query is already 230 chars long.
You need to foresee this because players can have up to 2.1 billion dollars (32-bit integer), even score, bankaccount and other values might get that high.

Make it at least 350 chars long and try again.
I'll try that as soon as i get on my pc
Reply
#6

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
Your DB_Query variable you use to send the update query is too short.
When you replace the %d with 1234567890 (which is 10 chars long and is the length of an integer as text), the query gets to 342 characters long, yours is only 256 chars long.
Even without replacing the %d with any value, your query is already 230 chars long.
You need to foresee this because players can have up to 2.1 billion dollars (32-bit integer), even score, bankaccount and other values might get that high.

Make it at least 350 chars long and try again.
I just tried it but it's not working :/

EDIT:

here are the logs of MYSQL

PHP код:
[13:15:36] [DEBUGmysql_init_options()
[
13:15:36] [DEBUGmysql_init_options: return value'1'
[13:15:36] [DEBUGmysql_set_option(10)
[
13:15:36] [DEBUGmysql_set_option: return value'1'
[13:15:36] [DEBUGmysql_connect("localhost""root""*****""testone"1)
[
13:15:36] [DEBUGCHandleManager::Create(this=0x300898host='localhost'user='root'pass='****'db='testone'options=0x386868)
[
13:15:36] [WARNINGmysql_connectno password specified
[13:15:36] [DEBUGCConnection::CConnection(this=0x341d08host='localhost'user='root'passw='****'db='testone'options=0x386868)
[
13:15:36] [DEBUGCConnection::CConnection - new connection 0x3ac768
[13:15:36] [DEBUGCConnection::CConnection(this=0x4573020host='localhost'user='root'passw='****'db='testone'options=0x386868)
[
13:15:36] [DEBUGCConnection::CConnection - new connection 0x3ab3e0
[13:15:36] [DEBUGCThreadedConnection::WorkerFunc(this=0x4573020connection=0x4573020)
[
13:15:36] [DEBUGCThreadedConnection::CThreadedConnection(this=0x4573020connection=0x4573020)
[
13:15:36] [DEBUGCConnectionPool::CConnectionPool(size=2this=0x342388)
[
13:15:36] [DEBUGCConnection::CConnection(this=0x4748020host='localhost'user='root'passw='****'db='testone'options=0x386868)
[
13:15:36] [DEBUGCConnection::CConnection - new connection 0x3ab7c8
[13:15:36] [DEBUGCThreadedConnection::WorkerFunc(this=0x4748020connection=0x4748020)
[
13:15:36] [DEBUGCThreadedConnection::CThreadedConnection(this=0x4748020connection=0x4748020)
[
13:15:36] [DEBUGCConnection::CConnection(this=0x4915020host='localhost'user='root'passw='****'db='testone'options=0x386868)
[
13:15:36] [DEBUGCConnection::CConnection - new connection 0x3abbb0
[13:15:36] [DEBUGCThreadedConnection::WorkerFunc(this=0x4915020connection=0x4915020)
[
13:15:36] [DEBUGCThreadedConnection::CThreadedConnection(this=0x4915020connection=0x4915020)
[
13:15:36] [DEBUGCHandleManager::Create - new handle 0x364640
[13:15:36] [DEBUGmysql_connect: return value'1'
[13:15:36] [DEBUGmysql_errno(1)
[
13:15:36] [DEBUGCHandle::GetErrorId(this=0x364640)
[
13:15:36] [DEBUGCConnection::GetError(this=0x341d08connection=0x3ac768)
[
13:15:36] [DEBUGCHandle::GetErrorId - return valuetrueerror id'0'error msg''
[13:15:36] [DEBUGmysql_errno: return value'0'
[13:15:45] [DEBUGmysql_format(10x041E84BC3000"SELECT * FROM `PLAYERS` WHERE `USERNAME` = '%e' LIMIT 1")
[
13:15:45] [DEBUGCHandle::EscapeString(this=0x364640src='Test')
[
13:15:45] [DEBUGCConnection::EscapeString(src='Test'this=0x341d08connection=0x3ac768)
[
13:15:45] [DEBUGCHandle::EscapeString - return valuetrueescaped string'Test'
[13:15:45] [DEBUGmysql_format: return value'57'
[13:15:45] [DEBUGmysql_tquery(1"SELECT * FROM `PLAYERS` WHERE `USERNAME` = 'Test' LIMIT 1""OnPlayerDataCheck""ii")
[
13:15:45] [DEBUGCCallback::Create(amx=0x27cfdc0name='OnPlayerDataCheck'format='ii'params=0x41e84a0param_offset=5)
[
13:15:45] [DEBUGCCallback::Create callback index for 'OnPlayerDataCheck'31
[13:15:45] [DEBUGprocessing specifier 'i' with parameter index 0
[13:15:45] [DEBUGretrieved and pushed value '0'
[13:15:45] [DEBUGprocessing specifier 'i' with parameter index 1
[13:15:45] [DEBUGretrieved and pushed value '1'
[13:15:45] [DEBUGcreated delayed callback with 2 parameters
[13:15:45] [DEBUGCHandle::Execute(this=0x364640type=1query=0x3a3200)
[
13:15:45] [DEBUGCHandle::Execute - return valuetrue
[13:15:45] [DEBUGmysql_tquery: return value'1'
[13:15:45] [DEBUGCConnection::Execute(query=0x3a3200this=0x4573020connection=0x3ab3e0)
[
13:15:45] [DEBUGCQuery::Execute(this=0x3a3200connection=0x3ab3e0)
[
13:15:45] [DEBUGCResultSet::Create(connection=0x3ab3e0query_str='SELECT * FROM `PLAYERS` WHERE `USERNAME` = 'Test' LIMIT 1')
[
13:15:45] [DEBUGcreated new resultset '0x3eb8b8'
[13:15:45] [DEBUGfetched MySQL result '0x387468'
[13:15:45] [DEBUGallocated 0 bytes for PAWN result
[13:15:45] [DEBUGCCallback::Execute(amx=0x27cfdc0index=31num_params=2)
[
13:15:45] [DEBUGprocessing internal specifier 'c'
[13:15:45] [DEBUGpushed value '1' onto AMX stack
[13:15:45] [DEBUGprocessing internal specifier 'c'
[13:15:45] [DEBUGpushed value '0' onto AMX stack
[13:15:45] [DEBUGexecuting AMX callback with index '31'
[13:15:45] [DEBUGcache_get_row_count(0x041EB838)
[
13:15:45] [DEBUGcache_get_row_count: return value'1'
[13:15:45] [DEBUGAMX callback executed with error '0'
[13:15:51] [DEBUGmysql_format(10x041E8BB43000"INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('%e', '%s', '%e', '20', '0', '0', '0')")
[
13:15:51] [DEBUGCHandle::EscapeString(this=0x364640src='Test')
[
13:15:51] [DEBUGCConnection::EscapeString(src='Test'this=0x341d08connection=0x3ac768)
[
13:15:51] [DEBUGCHandle::EscapeString - return valuetrueescaped string'Test'
[13:15:51] [DEBUGCHandle::EscapeString(this=0x364640src='peQ;U3<SCZ')
[
13:15:51] [DEBUGCConnection::EscapeString(src='peQ;U3<SCZ'this=0x341d08connection=0x3ac768)
[
13:15:51] [DEBUGCHandle::EscapeString - return valuetrueescaped string'peQ;U3<SCZ'
[13:15:51] [DEBUGmysql_format: return value'298'
[13:15:51] [DEBUGmysql_tquery(1"INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('Test', 'E9958A1A4DE7CE6280A7D5D39C06FFAFEFB6FFA337A74E86BCAA5FBA2B180416', 'peQ;U3<SCZ', '20', '0', '0', '0')""OnPlayerRegister""d")
[
13:15:51] [DEBUGCCallback::Create(amx=0x27cfdc0name='OnPlayerRegister'format='d'params=0x41e8b9cparam_offset=5)
[
13:15:51] [DEBUGCCallback::Create callback index for 'OnPlayerRegister'51
[13:15:51] [DEBUGprocessing specifier 'd' with parameter index 0
[13:15:51] [DEBUGretrieved and pushed value '0'
[13:15:51] [DEBUGcreated delayed callback with 1 parameter
[13:15:51] [DEBUGCHandle::Execute(this=0x364640type=1query=0x3a3758)
[
13:15:51] [DEBUGCHandle::Execute - return valuetrue
[13:15:51] [DEBUGmysql_tquery: return value'1'
[13:15:51] [DEBUGCConnection::Execute(query=0x3a3758this=0x4573020connection=0x3ab3e0)
[
13:15:51] [DEBUGCQuery::Execute(this=0x3a3758connection=0x3ab3e0)
[
13:15:51] [ERRORerror #1136 while executing query "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('Test', 'E9958A1A4DE7CE6280A7D5D39C06FFAFEFB6FFA337A74E86BCAA5FBA2B180416', 'peQ;U3<SCZ', '20', '0', '0', '0')": Column count doesn't match value count at row 1
[13:15:51] [DEBUGCConnection::GetError(this=0x4573020connection=0x3ab3e0)
[
13:15:51] [DEBUGCCallback::Create(amx=0x27cfdc0name='OnQueryError'format='dsssd) 
Reply
#7

So is it DB_Query or there's another thing causing this?
Reply
#8

Looks like you've miscounted the columns you're trying to insert.

pawn Код:
[13:15:51] [ERROR] error #1136 while executing query "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('Test', 'E9958A1A4DE7CE6280A7D5D39C06FFAFEFB6FFA337A74E86BCAA5FBA2B180416', 'peQ;U3<SCZ', '20', '0', '0', '0')": Column count doesn't match value count at row 1
You've put 17 columns but only 7 values.
Reply
#9

Quote:
Originally Posted by DobbysGamertag
Посмотреть сообщение
Looks like you've miscounted the columns you're trying to insert.

pawn Код:
[13:15:51] [ERROR] error #1136 while executing query "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('Test', 'E9958A1A4DE7CE6280A7D5D39C06FFAFEFB6FFA337A74E86BCAA5FBA2B180416', 'peQ;U3<SCZ', '20', '0', '0', '0')": Column count doesn't match value count at row 1
You've put 17 columns but only 7 values.
PHP код:
cache_get_value_int(0"ID"PlayerInfo[playerid][pID]);
                
cache_get_value_int(0"KILLS"PlayerInfo[playerid][pKills]);
                
cache_get_value_int(0"DEATHS"PlayerInfo[playerid][pDeaths]);
                
cache_get_value_int(0"SCORE"PlayerInfo[playerid][pScore]);
                
cache_get_value_int(0"CASH"PlayerInfo[playerid][pCash]);
                
                
cache_get_value_int(0"BAN"PlayerInfo[playerid][pBan]);
                
cache_get_value_int(0"IP"PlayerInfo[playerid][pIP]);
                
cache_get_value_int(0"ADMIN"PlayerInfo[playerid][pAdmin]);
                
cache_get_value_int(0"WARNINGS"PlayerInfo[playerid][pWarnings]);
                
cache_get_value_int(0"VIP"PlayerInfo[playerid][pVIP]);
                
cache_get_value_int(0"TOKENS"PlayerInfo[playerid][pToken]);
                
cache_get_value_int(0"CHAT"PlayerInfo[playerid][pChat]);
                
cache_get_value_int(0"SKIN"PlayerInfo[playerid][pSkin]);
                
cache_get_value_int(0"NAMECHANGES"PlayerInfo[playerid][pNamechanges]);
                
cache_get_value_int(0"MODE"PlayerInfo[playerid][pMODE]); 
I have all the values but i didn't wanna put all of them because of the spam
Reply
#10

UPDATE:

I tried this on a simple gamemode (like grandlarc) and everything worked..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)