#1

pawn Код:
CMD:unban(playerid, params[])
{
    if(PlayerData[playerid][AdminLevel] < 2) return SendUnathorizedMessage(playerid);
   
    new account[126], string[126], szQuery[2056], zExist = 0, zBanned = 0, IPAdrs[16];
    if(sscanf(params, "s[126]", account)) return SendClientMessage(playerid, COLOR_SEABLUE, "Syntax:{FFFFFF} /unban [Exact Player Name]");
   
    mysql_format(Mysql_users, szQuery, sizeof(szQuery), "%e", account);
    mysql_format(Mysql_users, query, sizeof(query), "SELECT `Banned` FROM `accounts` WHERE Fullname='%e'", szQuery);
    new Cache: result = mysql_query(Mysql_users, query);

    if(cache_num_rows() >= 0)
    {
        zBanned = cache_get_field_content_int(0, "Banned", Mysql_users);
        if(zBanned)
        {
            cache_get_field_content(0, "IPAddress", IPAdrs, Mysql_users, 16);
            mysql_format(Mysql_users, query, sizeof(query), "UPDATE `accounts` SET Banned='0', BanReason='Not Banned', BannedBy='Not banned' WHERE `Fullname` = '%e'", szQuery);
            mysql_tquery(Mysql_users, query, "", "");
            format(string, sizeof(string), "unbanip %s", IPAdrs);
            printf("%s unbanned %s (%s)", GetPlayersName(playerid), query, IPAdrs);
            format(string, sizeof(string), "You have unbanned the account '%s'", query);
            SendClientMessage(playerid, -1, string);
            SendRconCommand(string);
        }
        else {
            SendClientMessage(playerid, COLOR_PALERED, "Error:{FFFFFF} That account isn't currently banned from the server.");
        }
    }
    else {
        format(string, sizeof(string), "Error:{FFFFFF} The account '%s' does not exist in the servers database.", account);
        SendClientMessage(playerid, COLOR_PALERED, string);
    }
    cache_delete(result);
    return 1;
}
EDIT:
All fixed, nothing was wrong with the code, I was just selecting the wrong table *derp*
Reply
#2

change
Quote:

if(cache_num_rows() >= 0)

to
Quote:

if(cache_num_rows() > 0)

Reply
#3

Quote:
Originally Posted by rickisme
Посмотреть сообщение
change

to
I tried that before, and it only works on row 1, and then for every other row it says the account doesn't exist.

Example:
Код:
Row 0 name = Jack
Row 1 name = Jack Leslie
Row 2 name = Bob
/unban Jack = account doesnt exist
/unban Jack Leslie = account exists but isnt banned (code works)
/unban Bob = account doesnt exist
Reply
#4

are you try debug the query ?

put
pawn Код:
printf("Query : %s", query);
after
pawn Код:
new Cache: result = mysql_query(Mysql_users, query);
Reply
#5

Код:
printf("%s - %d", query, cache_num_rows());

[13:33:53] SELECT `Banned` FROM `accounts` WHERE Fullname='Jack' - 0
[13:33:59] SELECT `Banned` FROM `accounts` WHERE Fullname='Jack Leslie' - 1
[13:34:03] SELECT `Banned` FROM `accounts` WHERE Fullname='Pidgeon' - 0
Reply
#6

are you try paste that query to your mysql console to see result ?

Because i think it's your database problem, not the script
Reply
#7

The sql syntax is fine, i just checked it.
Reply
#8

cache_num_row() return the number of rows from a result set, not row index

Do you have teamviewer ? i can help you via teamviewer
Reply
#9

Fixed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)