SA-MP Forums Archive
Problem with MySQL Data Loading - 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: Problem with MySQL Data Loading (/showthread.php?tid=456180)



Problem with MySQL Data Loading - Slepur - 04.08.2013

Hey,

I've created a MySQL dialog login system and it works fine... Until it attempts to load the players data when logging in. It just keeps everything set to 0.


enum:
Код:
enum pData
{
username[MAX_PLAYER_NAME],
password[32],
score,
money,
admin,
logged,
}
new playerdata[MAX_PLAYERS][pData];
loginplayer stock:
Код:
stock LoginPlayer(playerid, pass[])
{
    new query[1000];
    format(query, sizeof(query),"SELECT * FROM playerdata WHERE username = '%s' AND password = md5('%s')",playerdata[playerid][username],pass);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        if(mysql_fetch_row(query, "|"))
        {
            sscanf(query,"e<p<|>s[180]s[180]iii>", playerdata[playerid]);
            new str[80];
            format(str, sizeof(str),"Welcome %s, you have been logged in to your account",playerdata[playerid][username]);
            SendClientMessage(playerid, COLOR_BLUE, str);
            SetPlayerInterior(playerid, 0);
            SetPlayerVirtualWorld(playerid, 0);
            SetPlayerScore(playerid, playerdata[playerid][score]);
            GivePlayerMoney(playerid, playerdata[playerid][money]);
            SpawnPlayer(playerid);
            playerdata[playerid][logged] = 1;
        }
    }
    else
    {
        ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"Login to Account.","Wrong password:","Login","Cancel");
    }
}



Re: Problem with MySQL Data Loading - Slepur - 04.08.2013

Just messed around with it a bit and was still unsuccessful on getting it working.


Re: Problem with MySQL Data Loading - HarrisonC - 04.08.2013

I have no idea what you just did with that sscanf call but my method around retrieving data is probably a bit less advanced.

An example can be seen below

Код:
new temptext[255];

while(mysql_retrieve_row())
{
    mysql_fetch_field_row(temptext, "DatabaseColumnName");
    someValue = strval(temptext);
}



Re: Problem with MySQL Data Loading - CrazyChoco - 04.08.2013

Why don't you use mysql r31? It's easiere and better. Anyway your issue might be the sscanf.


Re: Problem with MySQL Data Loading - SuperViper - 04.08.2013

You're sending a query with the username as one of the values you're trying to load. Unless you're actually assigning the playerdata username variable beforehand, you need to actually fetch the persons name to put in the query.

Also, mysql_fetch_row is just used like

pawn Код:
mysql_fetch_row(query);