SA-MP Forums Archive
Checking if account exists - 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: Checking if account exists (/showthread.php?tid=562546)



Checking if account exists - Luis- - 09.02.2015

This isn't working as I'd like it too.
pawn Код:
stock AccountExists(playerid, name[]) {
    new Query[128];
    format(Query, sizeof Query, "SELECT `Name` FROM `accounts` WHERE `Name` = '%s'", name);
    mysql_tquery(dbHandle, Query, "AccountReturn", "i", playerid);
    return 1;
}

forward AccountReturn(playerid);
public AccountReturn(playerid) {
    new rows, fields;
    cache_get_data(rows, fields, dbHandle);
    if(rows) {
        return 1;
    }
    return 0;
}
I have a master account system, where you need to register your master account and then create a character, so the function will check if the character name already exists in the database, but it doesn't work properly.


Re: Checking if account exists - HazardouS - 09.02.2015

There is nothing wrong with the code as far as I can tell, what is the problem with it?


Re: Checking if account exists - Luis- - 09.02.2015

Sorry, forgot to mention that. It just tells me the account exists even though it's not in the database.


Re: Checking if account exists - Sawalha - 09.02.2015

try using this query string:
pawn Код:
format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name`='%s' LIMIT 1", name);
this selects all accounts have the name which is valued as 'name' and '%s' in the format code, "LIMIT 1" for selecting 1 result that has that name.


Re: Checking if account exists - Luis- - 09.02.2015

Just updated it, still says it exists when it doesn't. I'm completely confused.


Re: Checking if account exists - Sawalha - 09.02.2015

can you show me your name checking code?


Re: Checking if account exists - Luis- - 09.02.2015

pawn Код:
mysql_escape_string(inputtext, username);
if(AccountExists(playerid, username)) {
    SendClientMessage(playerid, COLOR_GREY, "This character name is already being used, please try another one!");
    ShowPlayerDialog(playerid, DIALOG_ADD_CHAR, DIALOG_STYLE_INPUT, "Character Add", "Now you need to add a character to your master account\nExample: John_Doe", "Add", "");
}



Re: Checking if account exists - Sime30 - 09.02.2015

Luis, I have a similar /changename function which checks for a name.
Let me check for it


Re: Checking if account exists - HazardouS - 09.02.2015

I would add some debug messages to see what's the name passed as parameter for AccountExists function.


Re: Checking if account exists - Sime30 - 09.02.2015

Well, I think your stock/check is wrong.

This is how my working code looks like

pawn Код:
// change name cmd
mysql_format(MySQLHandle, Query, sizeof(Query), "SELECT * FROM users WHERE PlayerName = '%s' LIMIT 1", newname);
    mysql_tquery(MySQLHandle, Query, "OnAccountChangeName", "iis", playerid,id, newname);

forward OnAccountChangeName(playerid, id, newname[]);
public OnAccountChangeName(playerid, id, newname[])
{
    if(cache_num_rows()) return SendClientMessage(playerid, COLOR_ERROR, "This name is in use!");
    // ....
    return 1;
}