SA-MP Forums Archive
MySQL: Server says account exists when it does not - 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: MySQL: Server says account exists when it does not (/showthread.php?tid=388618)



MySQL: Server says account exists when it does not - NewerthRoleplay - 29.10.2012

Hey I am making a mysql login/register system however I am having a problem where when I login it says my account exists however there is no accounts in the table.
Here is the OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
    new Query[512], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE Username='%s'", name);
    mysql_function_query(dbconnect, Query, false, "OnQueryFinish", "");
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login","Enter your password below to login","Login","Cancel");
    }
    else
    {
        ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Register","Enter your password below to register:","Register","Cancel");
    }
    mysql_free_result();
    return 1;
}
Here is the rest of the login /register script as I do not feel it is working properly or the most efficient method of storing a large quantity of data.

The login and register dialog's
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch (dialogid)
    {
        case LOGIN_DIALOG:
        {
            if(!response)
            {
                SendClientMessage(playerid, COLOR_LIGHTRED,"You need to be logged in!");
                Kick(playerid);
            }
            LoginPlayer(playerid, inputtext);
        }
        case REGISTER_DIALOG:
        {
            if(!response)
            {
                SendClientMessage(playerid, COLOR_LIGHTRED,"You need to be logged in!");
                Kick(playerid);
            }
            new query[512], username[MAX_PLAYER_NAME];
            GetPlayerName(playerid, username, sizeof(username));
            format(query, sizeof(query),"INSERT INTO `Users` (Username,Password) VALUES ('%s',md5('%s'))",username, inputtext);
            mysql_function_query(dbconnect, query, false, "OnQueryFinish", "");
            ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login","Enter your password below to login:","Login","Cancel");
        }
    }
    return 1;
}
The stocks.
pawn Код:
stock LoginPlayer(playerid, pass[])
{
    new query[1000], username[MAX_PLAYER_NAME];
    GetPlayerName(playerid, username, sizeof(username));
    format(query, sizeof(query),"SELECT * FROM `Users` WHERE Username = '%s' AND password = md5('%s')",username, pass);
    mysql_function_query(dbconnect, query, false, "OnQueryFinish", "");
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        if(mysql_fetch_row_format(query, "|"))
        {
            sscanf(query,"e<p<|>s[24]s[32]iiiiiiiiiiiiiifffiii>", PlayerInfo[playerid]);
            new str[80];
            format(str, sizeof(str),"Welcome %s, you have been loged to your account",username);
            SendClientMessage(playerid, COLOR_BLUE, str);
            SetPlayerInterior(playerid, 0);
            SetPlayerVirtualWorld(playerid, 0);
            SpawnPlayer(playerid);
        }
    }
    else
    {
        ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login.","Wrong password:","Login","Cancel");
    }
}
stock SavePlayerStats(playerid)
{
        new squery[1000];
        GetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
        format(squery, sizeof(squery), "UPDATE Users SET Sex = %d,Age = %d, Origin = %d, Warns = %d, Money = %d, Level = %d, VIP = %d, Admin = %d, Tester = %d, Kills = %d, Deaths = %d, Muted = %d, Jailed = %d, Banned = %d, X = %f, Y = %f, Z = %f, Job = %d, Faction = %d, Rank = %d, WHERE username='%s'", PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pOrigin], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pTester], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank]);
        mysql_function_query(dbconnect, squery, false, "OnQueryFinish", "");
        mysql_free_result();
}



Re: MySQL: Server says account exists when it does not - NewerthRoleplay - 29.10.2012

mysql log:
pawn Код:
[21:58:55] >> mysql_query_callback( Connection handle: 1 )
[21:58:55] >> mysql_store_result( Connection handle: 1 )
[21:58:55] CMySQLHandler::StoreResult() - No data to store.
[21:58:55] >> mysql_num_rows( Connection handle: 1 )
[21:58:55] CMySQLHandler::NumRows() - You cannot call this function now. (Reason: Dead Connection)
[21:58:55] >> mysql_free_result( Connection handle: 1 )
[21:58:55] CMySQLHandler::FreeResult() - The result is already empty.
[21:58:55] Passing query SELECT * FROM `Users` WHERE Username='Connor_Howell' |
[21:58:55] ProcessQueryThread(OnQueryFinish) - Query was successful. (SELECT * FROM `Users` WHERE Username='Connor_Howell')
[21:58:55] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[21:58:55] OnQueryFinish() - Threaded function called.
[21:58:59] >> mysql_query_callback( Connection handle: 1 )
[21:58:59] >> mysql_store_result( Connection handle: 1 )
[21:58:59] CMySQLHandler::StoreResult() - Result was stored.
[21:58:59] >> mysql_num_rows( Connection handle: 1 )
[21:58:59] CMySQLHandler::NumRows() - Returned 0 row(s)
[21:58:59] Passing query SELECT * FROM `Users` WHERE Username = '' AND password = md5('') |
[21:58:59] ProcessQueryThread(OnQueryFinish) - Query was successful. (SELECT * FROM `Users` WHERE Username = '' AND password = md5(''))
[21:58:59] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[21:58:59] OnQueryFinish() - Threaded function called.



Re: MySQL: Server says account exists when it does not - Vince - 29.10.2012

Threaded queries cannot immediately be retrieved after you've sent them. That's the whole point of threads. The MySQL server will call your specified Pawn function (OnQueryFinish) as soon as it's done executing.


Re: MySQL: Server says account exists when it does not - NewerthRoleplay - 29.10.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
Threaded queries cannot immediately be retrieved after you've sent them. That's the whole point of threads. The MySQL server will call your specified Pawn function (OnQueryFinish) as soon as it's done executing.
thanks I fixed that but now I am having problems with the stock to save the user data, here it is:
pawn Код:
stock SavePlayerStats(playerid)
{
        new squery[1000], username[MAX_PLAYER_NAME];
        GetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
        GetPlayerName(playerid, username, sizeof(username));
        format(squery, sizeof(squery), "UPDATE Users SET Sex = %d,Age = %d, Origin = %d, Warns = %d, Money = %d, Level = %d, VIP = %d, Admin = %d, Tester = %d, Kills = %d, Deaths = %d, Muted = %d, Jailed = %d, Banned = %d, X = %f, Y = %f, Z = %f, Job = %d, Faction = %d, Rank = %d, WHERE username='%s'", PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pOrigin], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pTester], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank], username);
        mysql_function_query(dbconnect, squery, false, "OnQueryFinish", "");
        mysql_free_result();
}
I forgot to add the errors -.-
Код:
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(366) : error 075: input line too long (after substitutions)
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(367) : error 017: undefined symbol "P"
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(368) : warning 217: loose indentation
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(368) : error 017: undefined symbol "layerInfo"
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(368) : warning 215: expression has no effect
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(368) : error 001: expected token: ";", but found "]"
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(368) : error 029: invalid expression, assumed zero
Y:\Documents\SpectralRP\gamemodes\spectral.pwn(368) : fatal error 107: too many error messages on one line



Re: MySQL: Server says account exists when it does not - Edvin - 29.10.2012

Are you using mysql R7, or why do you use mysql_query_function? ... Use mysq_query.


Re: MySQL: Server says account exists when it does not - NewerthRoleplay - 29.10.2012

Quote:
Originally Posted by Edvin
Посмотреть сообщение
Are you using mysql R7, or why do you use mysql_query_function? ... Use mysq_query.
Im using mysql_function_query as yes I am using BlueG's R7 version of the a_mysql include and plugin.


Re: MySQL: Server says account exists when it does not - fubar - 29.10.2012

Try something like this to save the info,but you may need to mess around with it to perfect it

Код:
stock SavePlayerStats(playerid)
{
        new squery[1000], username[MAX_PLAYER_NAME];
        GetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
        GetPlayerName(playerid, username, sizeof(username));
        format(squery, sizeof(squery), "UPDATE Users SET Sex = %d,Age = %d, Origin = %d, Warns = %d, Money = %d, Level = %d, VIP = %d, Admin = %d",PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pOrigin], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pAdmin]);
        format(squery, sizeof(squery), "%s,Tester = %d, Kills = %d, Deaths = %d, Muted = %d, Jailed = %d, Banned = %d, X = %f, Y = %f", szQuery, PlayerInfo[playerid][pTester], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY]);
	format(squery, sizeof(squery), "%s,Z = %f, Job = %d, Faction = %d, Rank = %d, WHERE username='%s'", szQuery, PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank], username);
        mysql_function_query(dbconnect, squery, false, "OnQueryFinish", "");
        mysql_free_result();
}