Register / Login - MySQL Check Player
#1

Hi all! I want to make a better way to check the player info! ( If is registered / or not )

pawn Код:
// (Get User Account Info)
    new userquery[256];
    PlayerInfo[ playerid ][ Logged ] = 0;
    format(userquery, sizeof(userquery), "SELECT `Adress` FROM `users` WHERE `Name` = '%s' LIMIT 1", PlayerName2(playerid));
    mysql_query(userquery);
    mysql_store_result();
    new rows = mysql_num_rows();
    if(!rows)
    {
        new rstring[256];
        format(rstring,256,""W"Welcome "YE"%s"W", on "R"San "S"Fierro "YE"Stuntage\n\n"W"Please "G"Register"W" to save your stats: "COL_ORANGE"Score,Money,Coins...", PlayerName2(playerid));
        ShowPlayerDialog(playerid,RegisterDialog,DIALOG_STYLE_PASSWORD,""W"Location:"G" Register Account",rstring,"(Register)","(Quit)");
    }
    if(rows == 1)
    {
        SCM:(playerid, ~1," ");
        SCM:(playerid, ~1,""W"Please "O"/"S"login "W"on server "NAME_S" "O""VERSION_S"");
        Info(playerid, "~w~Account ~g~~h~Registered ~w~type ~p~~h~/~r~~h~login");
        PlayerInfo[playerid][Registered] = 1;
    }
    mysql_free_result(); // Free
Reply
#2

This method is good.

Change
pawn Код:
if(!rows)
    {
        new rstring[256];
        format(rstring,256,""W"Welcome "YE"%s"W", on "R"San "S"Fierro "YE"Stuntage\n\n"W"Please "G"Register"W" to save your stats: "COL_ORANGE"Score,Money,Coins...", PlayerName2(playerid));
        ShowPlayerDialog(playerid,RegisterDialog,DIALOG_STYLE_PASSWORD,""W"Location:"G" Register Account",rstring,"(Register)","(Quit)");
    }
    if(rows == 1)
    {
        SCM:(playerid, ~1," ");
        SCM:(playerid, ~1,""W"Please "O"/"S"login "W"on server "NAME_S" "O""VERSION_S"");
        Info(playerid, "~w~Account ~g~~h~Registered ~w~type ~p~~h~/~r~~h~login");
        PlayerInfo[playerid][Registered] = 1;
    }
with
pawn Код:
if(!rows)
    {
        new rstring[256];
        format(rstring,256,""W"Welcome "YE"%s"W", on "R"San "S"Fierro "YE"Stuntage\n\n"W"Please "G"Register"W" to save your stats: "COL_ORANGE"Score,Money,Coins...", PlayerName2(playerid));
        ShowPlayerDialog(playerid,RegisterDialog,DIALOG_STYLE_PASSWORD,""W"Location:"G" Register Account",rstring,"(Register)","(Quit)");
    }
    else
    {
        SCM:(playerid, ~1," ");
        SCM:(playerid, ~1,""W"Please "O"/"S"login "W"on server "NAME_S" "O""VERSION_S"");
        Info(playerid, "~w~Account ~g~~h~Registered ~w~type ~p~~h~/~r~~h~login");
        PlayerInfo[playerid][Registered] = 1;
    }
Also, you should use MySQL R7 with caching, is much faster than Normal MySQL functions, or at least try to use only threaded queries.
Reply
#3

Ok... thx for advices!

ON: SELECT `Adress` FROM `users` WHERE `Name` = '%s' LIMIT 1

Should i replace `Adress` with * ?
Reply
#4

Quote:
Originally Posted by Anonym2009
Посмотреть сообщение
Ok... thx for advices!

ON: SELECT `Adress` FROM `users` WHERE `Name` = '%s' LIMIT 1

Should i replace `Adress` with * ?
No, you only need one column to check, to see if the account exists, with * you select all, you don't need all columns.

I am not advanced in MySQL, but when Adress is NULL, I think it won't be counted by SELECT query, if it can be NULL, change Adress with Name, or in which column you store player's name.
Reply
#5

Yeah it's a better way to replace it with `Name` cuz' Adress could be NULL
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)