Problem with MySQL Data Loading
#1

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");
    }
}
Reply
#2

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

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);
}
Reply
#4

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

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);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)