/changename already exist name help
#3

ALWAYS escape input by people to avoid SQL Injection.

Set `name` column as UNIQUE KEY, not only the searching will be faster but it will not continue searching if a row is found because it now knows there will never be duplicates.

In /changename:
pawn Code:
mysql_format(..., "UPDATE IGNORE `users` SET `name` = '%e' WHERE `name` = '%s'", ...);
mysql_tquery(handle, query, "OnPlayerNameChange", "ds", playerid, params);
In `OnPlayerNameChange` callback:
pawn Code:
// without `IGNORE` keyword, it would return error about duplicate key
// `IGNORE` literally ignores the error and does absolutely nothing (0 rows are affected)
// When the row is updated (sets the new name), the affected rows will be 1
if (!cache_affected_rows())
{
    // already registered name, pick a new one
}
else
{
    // SetPlayerName
}
Reply


Messages In This Thread
/changename already exist name help - by brianrestup - 29.03.2020, 01:05
Re: /changename already exist name help - by SiaReyes - 29.03.2020, 03:24
Re: /changename already exist name help - by Calisthenics - 29.03.2020, 08:59
Re: /changename already exist name help - by brianrestup - 29.03.2020, 10:47
Re: /changename already exist name help - by SiaReyes - 29.03.2020, 11:07
Re: /changename already exist name help - by MichiCZ - 29.03.2020, 14:45

Forum Jump:


Users browsing this thread: 1 Guest(s)