SA-MP Forums Archive
My check account with mysql dosen't work - 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 check account with mysql dosen't work (/showthread.php?tid=560055)



My check account with mysql dosen't work - TheCartman - 26.01.2015

Hi guys! I have a problem.

I just installed my server on mysql plugin (R39-2) with cache and I got a problem. When I enter on server, I always have to register my account again (even if it is already created on mysql table).

I put this in OnPlayerConnect:
PHP код:
new string[128];
format(stringsizeof(string), "SELECT * FROM `accounts` WHERE `username` = '%s'"plname);
mysql_function_query(dbHandlestringtrue"OnQueryFinish""ii"THREAD_CHECK_ACCOUNT_CONNECTplayerid); 
This in OnPlayerRequestClass
PHP код:
switch(gPlayerAccount[playerid])
{
case 
0DisplayDialogForPlayer(playerid2); //register
case 1DisplayDialogForPlayer(playerid1); //login

And this is the CallBack (OnQueryFinish)
PHP код:
public OnQueryFinish(resultidplayeridConnectionHandle)
{
    new 
szRowsszFields;
    if(
resultid != THREAD_NO_RESULT)
    {
        
cache_get_data(szRowsszFields);
    }
    switch(
resultid)
    {
        case 
THREAD_CHECK_ACCOUNT_CONNECT:
        {
            if (
szRows) {
                new 
data[130];            
                
cache_get_field_content(0"Registered"data);
                 
PlayerInfo[playerid][pReg] = strval(data);
                if (
PlayerInfo[playerid][pReg] == 1)
                    
gPlayerLogged[playerid] = 1;
                else 
                    
gPlayerLogged[playerid] = 0;
            } else {
                
gPlayerLogged[playerid] = 0;
            }
        }
    }
    return 
1;

Did you see any wrong? Thanks!


Re: My check account with mysql dosen't work - TheCartman - 27.01.2015

UP! Any solution please?


Re: My check account with mysql dosen't work - TheCartman - 27.01.2015

Really no solution here? Can you give me another idea to make a function for checkin if account exists? Please. I start to lose players...


Re: My check account with mysql dosen't work - Sime30 - 27.01.2015

Follow this thread https://sampforum.blast.hk/showthread.php?tid=485633

EDIT: Also, you don't have to use "cache get data" and "(rows)" as written in this thread, use it just like this when you have done everything else.

pawn Код:
if(cache_num_rows())
    {



Re: My check account with mysql dosen't work - tyler12 - 27.01.2015

enable mysql debugging and post the outcome here.


Re: My check account with mysql dosen't work - TheCartman - 28.01.2015

Quote:
Originally Posted by Sime30
Посмотреть сообщение
Follow this thread https://sampforum.blast.hk/showthread.php?tid=485633

EDIT: Also, you don't have to use "cache get data" and "(rows)" as written in this thread, use it just like this when you have done everything else.

pawn Код:
if(cache_num_rows())
    {
I followed that tutorial all this time, I corrected my job everywhere. Now, my account is checked if exists or not, but variables don't save / don't load! It's written in database only when account is created.
That how I maded the Update function:
PHP код:
public Update (playeridtype) {
    new var[
128];
    
    switch (
type) {
        case 
pLevelx: {
            
format (var,128,"UPDATE `accounts` SET `Level` = '%d' WHERE `Username`='%s'"PlayerInfo[playerid][pLevel], PlayerName(playerid));
            
mysql_tquery (dbHandle, var, "OnQueryFinish""ii"THREAD_NO_RESULTplayerid);
        }
        case 
pAdminx: {
            
format (var,128,"UPDATE `accounts` SET `AdminLevel` = '%d' WHERE `Username`='%s'"PlayerInfo[playerid][pAdmin], PlayerName(playerid));
            
mysql_tquery (dbHandle, var, "OnQueryFinish""ii"THREAD_NO_RESULTplayerid);
        }
        case 
pDonateRankx: {
            
format (var,128,"UPDATE `accounts` SET `DonateRank` = '%d' WHERE `Username`='%s'"PlayerInfo[playerid][pDonateRank], PlayerName(playerid));
            
mysql_tquery (dbHandle, var, "OnQueryFinish""ii"THREAD_NO_RESULTplayerid);
        }
        case 
pSPos_xx: {
            
format (var,128,"UPDATE `accounts` SET `SPos_x` = '%f' WHERE `Username`='%s'"PlayerInfo[playerid][pSPos_x], PlayerName(playerid));
            
mysql_tquery (dbHandle, var, "OnQueryFinish""ii"THREAD_NO_RESULTplayerid);
        }
        case 
pSPos_yx: {
            
format (var,128,"UPDATE `accounts` SET `SPos_y` = '%f' WHERE `Username`='%s'"PlayerInfo[playerid][pSPos_y], PlayerName(playerid));
            
mysql_tquery (dbHandle, var, "OnQueryFinish""ii"THREAD_NO_RESULTplayerid);
        }
        case 
pSPos_zx: {
            
format (var,128,"UPDATE `accounts` SET `SPos_z` = '%f' WHERE `Username`='%s'"PlayerInfo[playerid][pSPos_z], PlayerName(playerid));
            
mysql_tquery (dbHandle, var, "OnQueryFinish""ii"THREAD_NO_RESULTplayerid);
        }
        case 
pSPos_rx: {
            
format (var,128,"UPDATE `accounts` SET `SPos_r` = '%f' WHERE `Username`='%s'"PlayerInfo[playerid][pSPos_r], PlayerName(playerid));
            
mysql_tquery (dbHandle, var, "OnQueryFinish""ii"THREAD_NO_RESULTplayerid);
        }
    }
    return 
1;

Ofc, I defined the cases (from 1 to 7) and I put this on OnPlayerDisconnect.
PHP код:
for (new 0NUMBER_OF_QUERIESi++) // NUMBER_OF_QUERIES defined as 10
    
Update (playeridi); 
And load function:
PHP код:
PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0"Level");
PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0"AdminLevel");                 
PlayerInfo[playerid][pSPos_x] = cache_get_field_content_int(0"SPos_x"); 
PlayerInfo[playerid][pSPos_y] = cache_get_field_content_int(0"SPos_y"); 
PlayerInfo[playerid][pSPos_z] = cache_get_field_content_int(0"SPos_z"); 
PlayerInfo[playerid][pSPos_r] = cache_get_field_content_int(0"SPos_r"); 
PlayerInfo[playerid][pDonateRank] = cache_get_field_content_int(0"DonateRank"); 
But I still didn't understand what's with that "cache_num_rows()", what you said. I didn't replace yet.
Anyway. Thanks for help. +reped.


Re: My check account with mysql dosen't work - TheCartman - 29.01.2015

Up...


Re: My check account with mysql dosen't work - Sime30 - 29.01.2015

Complications, complications and complications... First of all, UPDATE only pos X , pos Y and pos Z on disconnect. Things like level , donate rank etc UPDATE when it changes. Second: Why do you need that type? Save it normally, like the God commands! Third, look at my codes below ----

pawn Код:
SaveAccount(playerid)
{
      new Query[ 300 ];
      mysql_format(MySQLHandle, Query, sizeof(Query), "UPDATE  users SET  SKILL_M4  = %d,  SKILL_SNIPERRIFLE  = %d WHERE  IDPlayer  = %d", PlayaInfo[ playerid ][ SKILL_M4 ], PlayaInfo[ playerid ][ SKILL_SNIPERRIFLE ], PlayaInfo[ playerid ][ IDPlayer  ]);
      mysql_tquery(MySQLHandle, Query);
      //...
}
Extra notes: When you are updating, just use mysql_tquery(Handle, Query); , there is no need for callbacks. Use callbacks when you are SELECTing or INSERTing.


cache_num_rows()


pawn Код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{

    if(cache_num_rows())
    {



Re: My check account with mysql dosen't work - TheCartman - 29.01.2015

Quote:
Originally Posted by Sime30
Посмотреть сообщение
Complications, complications and complications... First of all, UPDATE only pos X , pos Y and pos Z on disconnect. Things like level , donate rank etc UPDATE when it changes. Second: Why do you need that type? Save it normally, like the God commands! Third, look at my codes below ----

pawn Код:
SaveAccount(playerid)
{
      new Query[ 300 ];
      mysql_format(MySQLHandle, Query, sizeof(Query), "UPDATE  users SET  SKILL_M4  = %d,  SKILL_SNIPERRIFLE  = %d WHERE  IDPlayer  = %d", PlayaInfo[ playerid ][ SKILL_M4 ], PlayaInfo[ playerid ][ SKILL_SNIPERRIFLE ], PlayaInfo[ playerid ][ IDPlayer  ]);
      mysql_tquery(MySQLHandle, Query);
      //...
}
Extra notes: When you are updating, just use mysql_tquery(Handle, Query); , there is no need for callbacks. Use callbacks when you are SELECTing or INSERTing.


cache_num_rows()


pawn Код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{

    if(cache_num_rows())
    {
I use that type for updating one by one. Like, when AdminLevel is changed, I will put just "Update(playerid, pAdminx);", I think it's faster then all that command, and it's easier to change... I will try to remake all gamemode, thanks for tip, I will be back if didn't work...


Re: My check account with mysql dosen't work - Sime30 - 29.01.2015

The speed is the same.
Come back when you do.