Check field in MySQL
#1

Okay, so say that I want to ban a player by their IP. I add their IP to 'bans' in phpmyadmin. How would I go about checking if their IP is in the database? And kicking them if their IP is in the database?

Sorry, i'm still trying to learn how to use MySQL.

Thanks,
DBan
Reply
#2

I just made this:
pawn Код:
COMMAND:test(playerid, params[])
{
    new query[128], user, ip_s[16];
    if(sscanf(params,"d",user)) return 1;
    GetPlayerIp(user,ip_s,16);
    format(query, 128, "SELECT * FROM ips WHERE ip=INET_ATON('%s') LIMIT 1",ip_s);
    mysql_query(query), mysql_store_result();
    if(mysql_num_rows())
    {
        Ban(user);
    } else SendClientMessage(playerid,-1,"The IP of this player wasn't found in the database.");
    mysql_free_result();
    return 1;
}
It should be something as that, I think.

I used two IPs for testing, one of them was my IP. I inserted them in the DB with INET_ATON format. If you want to extract them you can use INET_NTOA to 'decrypt' them.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)