SA-MP Forums Archive
SQL help - 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: SQL help (/showthread.php?tid=278663)



SQL help - Cowboy - 23.08.2011

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



Re: SQL help - Basicz - 23.08.2011

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


Re: SQL help - Cowboy - 23.08.2011

Didn't work, anything else?


Re: SQL help - Cowboy - 23.08.2011

Do I need to use strval?


Re: SQL help - [HiC]TheKiller - 23.08.2011

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


Re: SQL help - Cowboy - 24.08.2011

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] ?


AW: SQL help - Nero_3D - 24.08.2011

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



Re: SQL help - Cowboy - 25.08.2011

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?


Re: SQL help - Lorenc_ - 25.08.2011

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.


Re: SQL help - Cowboy - 25.08.2011

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

Rep to you aswell.