SQL help
#1

Hello, after retrieving the data when a player login and I want to set the admin level, how can I do it?

I've got this but it makes an error on the last line

pawn Code:
db_get_field_assoc(Result, "ADMINLEVEL", Field, 30);
PlayerInfo[playerid][pAdminLevel] = strval(Field);
Reply
#2

Would sends an error if you put:
pawn Code:
new
    Field[ 21 ]
;

db_get_field_assoc( Result,  "ADMINLEVEL",  Field,  30 ); // Array size does not match
Maybe try

pawn Code:
db_get_field_assoc( Result, "ADMINLEVEL", Field, sizeof Field );
?
Reply
#3

Didn't work, anything else?
Reply
#4

Do I need to use strval?
Reply
#5

Can I see your query? And yes, you do need strval.
Reply
#6

pawn Code:
if(dialogid == 2)
    {
        if(!response) return Kick(playerid);
        format(Query, sizeof(Query), "SELECT `NAME` FROM `USERS` WHERE `NAME` = '%s' AND `PASSWORD` = '%s'", pName, inputtext);
        Result = db_query(Database, Query);
        if(!db_num_rows(Result))
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Account", "Login to your account\nWrong password\n\nEnter your password:", "Login", "Quit");
        }
        else
        {
            new Field[30];
            db_get_field_assoc(Result, "ADMINLEVEL", Field, 30);
            PlayerInfo[playerid][pAdminLevel] = strval(Field);
            PlayerInfo[playerid][pLogged] = 1;
            SendClientMessage(playerid, Green, "You have logged in");
            db_free_result(Result);    
        }
    }
Now that code compiles fine now, idk why it didn't do it before, but it seems like it compiled now.
But it is not setting my adminlevel to whatever it retrieves from there.

I did this to find out but it just displayed 0

pawn Code:
COMMAND:test(playerid, params[])
{
    new string[128];
    format(string, sizeof(string), "Your admin level is: %d", PlayerInfo[playerid][pAdminLevel]);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Why doesn't it put the value into PlayerInfo[playerid][pAdminLevel] ?
Reply
#7

You only selected that name

pawn Code:
format(Query, sizeof(Query), "SELECT `ADMINLEVEL` FROM `USERS` WHERE `NAME` = '%s' AND `PASSWORD` = '%s'", pName, inputtext);
or just the whole line
pawn Code:
format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' AND `PASSWORD` = '%s'", pName, inputtext);
Reply
#8

That did it, thank you! Rep

Using this SQL Database Browser http://sqlitebrowser.sourceforge.net/

will I be able to edit a players account while he is online? Or only when he is offline?
Reply
#9

If you haven't notice, this problem in my tutorial has been fixed. Sorry about that. You can only edit his account while his offline.

Which I also assume you're using my system.
Reply
#10

Alright, thanks Lorenc_. And yes I am using your system, thanks for it, you saved me alot of time.

Rep to you aswell.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)