SA-MP Forums Archive
Check field in MySQL - 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: Check field in MySQL (/showthread.php?tid=356028)



Check field in MySQL - DBan - 02.07.2012

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


Respuesta: Check field in MySQL - [DOG]irinel1996 - 02.07.2012

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.