mysql - How to check if username exists
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
The problem is in your syntax, not in the MySQL check.

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 user 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.
    else
    {
        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;
}
Also what's the need for select *? You don't need to use any of the information in the columns, so there's no reason to select it all, if you have a lot of columns this may induce performance issues on the server.

Edit: Too late , anyway the select * stuff still applies
What do you mean with the "select *"?

I'm still new to mysql, but if i can improve my knownledge, that always nice
Reply


Messages In This Thread
mysql - How to check if username exists - by Naxix - 28.11.2010, 09:46
Re: mysql - How to check if username exists - by Retardedwolf - 28.11.2010, 09:47
Re: mysql - How to check if username exists - by XePloiT - 28.11.2010, 09:49
Re: mysql - How to check if username exists - by Naxix - 28.11.2010, 09:56
Re: mysql - How to check if username exists - by XePloiT - 28.11.2010, 09:59
Re: mysql - How to check if username exists - by Naxix - 28.11.2010, 10:06
Re: mysql - How to check if username exists - by JaTochNietDan - 28.11.2010, 10:06
Re: mysql - How to check if username exists - by XePloiT - 28.11.2010, 10:20
Re: mysql - How to check if username exists - by Naxix - 28.11.2010, 10:31
Re: mysql - How to check if username exists - by JaTochNietDan - 28.11.2010, 10:46

Forum Jump:


Users browsing this thread: 1 Guest(s)