mysql - How to check if username exists
#1

Hi, i've started to use mysql, but i have a problem.
How can i use mysql to check every registered username that are in my database?

Like i joined my server with the name "Naxix" then i want the database to check if "Naxix" is in the database. I tried with this code:

pawn Код:
dcmd_register(playerid,params[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new Query[200], Pname[24], escpname[24];
    GetPlayerName(playerid, Pname, 24);
    mysql_real_escape_string(Pname, escpname);
    format(Query, sizeof(Query), "SELECT * FROM `playerinfo` WHERE `user` = '%s'", escpname);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0) return SendClientMessage(playerid,COLOUR_RED,"This account name is already in use!"); // I tried with this, but it wont work, i was logged in but i can just keep register a new account.
    {
        new PIP[50],pass[128];
        GetPlayerName(playerid, Pname, 24);
        new escpass[100];
        if(sscanf(params,"s",pass)) return SendClientMessage(playerid,COLOUR_RED,"Usage: /register [Password]");
        mysql_real_escape_string(pass, escpass);
        mysql_real_escape_string(Pname, escpname);
        GetPlayerIp(playerid, PIP, 50);
        format(Query, sizeof(Query), "UPDATE `playerinfo` SET `score` = '%d',`money` = '%d' WHERE `user` = '%s'", GetPlayerScore(playerid), GetPlayerMoney(playerid), escpname);
    mysql_query(Query);
        GameTextForPlayer(playerid, "~g~Registered", 2000, 3);
        SendClientMessage(playerid, 0x0000D9AA, "Registered and Logged into your account!");
        SetPVarInt(playerid, "Logged", 1);
    }
    return 1;
}
I can just keep on register a new account.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)