Checking if account exists
#1

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.
Reply
#2

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

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

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.
Reply
#5

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

can you show me your name checking code?
Reply
#7

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", "");
}
Reply
#8

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

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

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)