MySQL Loading Error
#1

Hi, so my MySQL server is reading from the Database just fine (SELECT * FROM and stuff are working just fine). But my problem is that when I try to load something and store it into a variable, it doesn't load.


Load the info from the Database

pawn Код:
forward LoadAccount(playerid);
public LoadAccount(playerid)
{
    cache_get_row(0, 2, PlayerInfo[playerid][Password]);
    cache_get_row(0, 3, PlayerInfo[playerid][pIp]);
    PlayerInfo[playerid][pAge] = cache_get_row_int(0, 4);
    cache_get_row(0, 5, PlayerInfo[playerid][pSex]);
    cache_get_row(0, 6, PlayerInfo[playerid][pRace]);
    PlayerInfo[playerid][pSkin] = cache_get_row_int(0, 7);
    PlayerInfo[playerid][posx] = cache_get_row_float(0, 8);
    PlayerInfo[playerid][posy] = cache_get_row_float(0, 9);
    PlayerInfo[playerid][posz] = cache_get_row_float(0, 10);
    return 1;
}
What runs before the loading
pawn Код:
forward LoginPlayer(playerid);
public LoginPlayer(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {
        //SCM(playerid, COLOR_RED, "Ran - Loginplayer");
        TextDrawHideForPlayer(playerid, LoginRegister1);
        TextDrawHideForPlayer(playerid, LoginRegister2);
        TextDrawHideForPlayer(playerid, LoginRegister3);
        TextDrawHideForPlayer(playerid, LoginRegister4);
        TextDrawHideForPlayer(playerid, LoginRegister5);
        TextDrawHideForPlayer(playerid, LoginRegister6);
        TextDrawHideForPlayer(playerid, LoginRegister7);
        TextDrawHideForPlayer(playerid, LoginRegister8);
        format(msg, sizeof(msg), "~w~Welcome ~n~~y~   %s", GetNameEx(playerid));
        GameTextForPlayer(playerid, msg, 5000, 1);
        LoadAccount(playerid);
        SpawnPlayer(playerid);
    }
    else
    {
        ShowDialog(playerid, Show:<Login>,DIALOG_STYLE_INPUT,"{08088A}Eastside Gaming Roleplay", "{FFFFFF}Welcome to {08088A}Eastside Gaming Roleplay. {FFFFFF}We {04B404}did {FFFFFF}find youe account in our database.\nPlease enter the password you have associated with this account.\nThat password was not the correct one.", "Login", "Quit");
    }
    return 1;
}
What runs the above
pawn Код:
Dialog:Login(playerid, response, listitem, inputtext[])
{
    if (response)
    {
        if(isnull(inputtext))
        {
            ShowDialog(playerid, Show:<Login>,DIALOG_STYLE_INPUT,"{08088A}Eastside Gaming Roleplay", "{FFFFFF}Welcome to {08088A}Eastside Gaming Roleplay. {FFFFFF}We {04B404}did {FFFFFF}find youe account in our database.\nPlease enter the password you have associated with this account.\nThat password was not the correct one.", "Login", "Quit");
        }
        new escapedPlayerName[MAX_PLAYER_NAME], escapepass[100];
        mysql_real_escape_string(inputtext, escapepass);
        mysql_real_escape_string(PlayerInfo[playerid][pName], escapedPlayerName);

        format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `name` = '%s' AND `password` = '%s' LIMIT 0,1", escapedPlayerName, escapepass);
        mysql_function_query(handle, query, true, "LoginPlayer", "i", playerid);
    }
    else
    {
        Kick(playerid);
    }
    return 1;
}

The error I am getting.
pawn Код:
[21:06:05] [ERROR] cache_get_row_int - invalid datatype
[21:06:05] [WARNING] CMySQLResult::GetRowData - invalid row ('0') or field index ('10')
[21:06:05] [ERROR] cache_get_row_float - invalid datatype
Image of my database where it is loading from.
Reply
#2

The indexes in phpMyAdmin start from 1 but in PAWN start from 0. So you'll need to decrease it by 1 each one:
pawn Код:
forward LoadAccount(playerid);
public LoadAccount(playerid)
{
    cache_get_row(0, 1, PlayerInfo[playerid][Password]);
    cache_get_row(0, 2, PlayerInfo[playerid][pIp]);
    PlayerInfo[playerid][pAge] = cache_get_row_int(0, 3);
    cache_get_row(0, 4, PlayerInfo[playerid][pSex]);
    cache_get_row(0, 5, PlayerInfo[playerid][pRace]);
    PlayerInfo[playerid][pSkin] = cache_get_row_int(0, 6);
    PlayerInfo[playerid][posx] = cache_get_row_float(0, 7);
    PlayerInfo[playerid][posy] = cache_get_row_float(0, 8);
    PlayerInfo[playerid][posz] = cache_get_row_float(0, 9);
    return 1;
}
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The indexes in phpMyAdmin start from 1 but in PAWN start from 0. So you'll need to decrease it by 1 each one:
pawn Код:
forward LoadAccount(playerid);
public LoadAccount(playerid)
{
    cache_get_row(0, 1, PlayerInfo[playerid][Password]);
    cache_get_row(0, 2, PlayerInfo[playerid][pIp]);
    PlayerInfo[playerid][pAge] = cache_get_row_int(0, 3);
    cache_get_row(0, 4, PlayerInfo[playerid][pSex]);
    cache_get_row(0, 5, PlayerInfo[playerid][pRace]);
    PlayerInfo[playerid][pSkin] = cache_get_row_int(0, 6);
    PlayerInfo[playerid][posx] = cache_get_row_float(0, 7);
    PlayerInfo[playerid][posy] = cache_get_row_float(0, 8);
    PlayerInfo[playerid][posz] = cache_get_row_float(0, 9);
    return 1;
}
That worked THANKS! But now the only thing loading is the ints, the strings aren't loading.
Reply
#4

Quote:
Originally Posted by KtotheYle
Посмотреть сообщение
That worked THANKS! But now the only thing loading is the ints, the strings aren't loading.
https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row
Quote:

You have to provide the size (max_len) by yourself if you use an enum-array as destination.

That means you have to use
Код:
cache_get_row(0, 1, PlayerInfo[playerid][Password], .max_len = 256);
cache_get_row(0, 2, PlayerInfo[playerid][pIp], .max_len = 32);
//...
You'll probably have to adjust the length values.
Reply
#5

Quote:
Originally Posted by maddinat0r
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row


That means you have to use
Код:
cache_get_row(0, 1, PlayerInfo[playerid][Password], .max_len = 256);
cache_get_row(0, 2, PlayerInfo[playerid][pIp], .max_len = 32);
//...
You'll probably have to adjust the length values.
It said that it optional, that is why I left it out.
Reply
#6

Quote:
Originally Posted by maddinat0r
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row


That means you have to use
Код:
cache_get_row(0, 1, PlayerInfo[playerid][Password], .max_len = 256);
cache_get_row(0, 2, PlayerInfo[playerid][pIp], .max_len = 32);
//...
You'll probably have to adjust the length values.
Changed it to
pawn Код:
forward LoadAccount(playerid);
public LoadAccount(playerid)
{
    cache_get_row(0, 1, PlayerInfo[playerid][Password], 128);
    cache_get_row(0, 2, PlayerInfo[playerid][pIp], 44);
    PlayerInfo[playerid][pAge] = cache_get_row_int(0, 3);
    cache_get_row(0, 4, PlayerInfo[playerid][pSex], 7);
    cache_get_row(0, 5, PlayerInfo[playerid][pRace], 22);
    PlayerInfo[playerid][pSkin] = cache_get_row_int(0, 6);
    PlayerInfo[playerid][posx] = cache_get_row_float(0, 7);
    PlayerInfo[playerid][posy] = cache_get_row_float(0, 8);
    PlayerInfo[playerid][posz] = cache_get_row_float(0, 9);
    return 1;
}
Still nothing, and yes those values(String lengths) are the right ones that are associated with the Database and the script variables.
Reply
#7

Bump bump bump it up
Reply
#8

Fixed, thanks for the help +rep you both.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)