Mysql Delete data... -
daghost111 - 29.11.2016
Hello.Im using godfather account ban system for my server.It works good to /ban player and it stores the data on mysql database.The problem is with command /unban[playername].If i do /unban it wont delete the name of that player from "bans" table on mysq,so player wont get unbaned.
This is the ban line that stores the data:
Код:
new q[400];
new ip[16];
GetPlayerIp(giveplayerid, ip, sizeof(ip));
//AddBan(ip);
format(q, sizeof(q), "INSERT INTO bans (id, name, reason, ban_time, issue_time, expiry_time, admin, ip) VALUES ('', '%s', '%s', %d, %d, %d, '%s', '%s')", namegive, reason, time, curtime, expire, name, ip);
mysql_query(q, THREAD_INSERT_BAN);
new banid = mysql_insert_id();
I dont know much about mysql,so i want to ask you how to remove(delete) players from database when i use /unban.
This is the unban cmd:
Код:
CMD:unban(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pBanAppealer] >= 1)
{
new string[128];
if(isnull(params)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /unban [playername]");
if(doesAccountExist(params))
{
OnPlayerOfflineLogin(params);
if( PlayerInfo[MAX_PLAYERS][pPermaBanned] == 3 )
{
SendClientMessageEx( playerid, COLOR_WHITE, "Permanently banned accounts can only be unbanned via FTP." );
}
else
{
if( PlayerInfo[MAX_PLAYERS][pBanned] >= 0)
{
PlayerInfo[MAX_PLAYERS][pBanned] = 0;
PlayerInfo[MAX_PLAYERS][pWarns] = 0;
PlayerInfo[MAX_PLAYERS][pDisabled] = 0;
RemoveBan(PlayerInfo[MAX_PLAYERS][pIP]);
print("OnPlayerOfflineLogin: Saving variables to file");
OnPlayerOfflineSave(params);
print("OnPlayerOfflineLogin: Variables saved properly");
format(string, 128, "AdmCmd: %s (IP:%s) was unbanned by %s.", params, PlayerInfo[MAX_PLAYERS][pIP], GetPlayerNameEx(playerid));
ABroadCast(COLOR_LIGHTRED,string,2);
new year, month,day;
getdate(year, month, day);
format(string, sizeof(string), "AdmCmd: %s (IP:%s) was unbanned by %s. (%d-%d-%d)", params, PlayerInfo[MAX_PLAYERS][pIP], GetPlayerNameEx(playerid),month,day,year);
Log("logs/ban.log", string);
print(string);
}
else
{
SendClientMessageEx( playerid, COLOR_WHITE, "Not a banned account!" );
}
}
}
else
{
SendClientMessageEx( playerid, COLOR_WHITE, "That account doesn't exist." );
}
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
}
return 1;
}
Thank you!
Re: Mysql Delete data... -
StrikerZ - 29.11.2016
PHP код:
CMD:unban(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pBanAppealer] >= 1)
{
new string[128];
if(isnull(params)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /unban [playername]");
if(doesAccountExist(params))
{
OnPlayerOfflineLogin(params);
if( PlayerInfo[MAX_PLAYERS][pPermaBanned] == 3 )
{
SendClientMessageEx( playerid, COLOR_WHITE, "Permanently banned accounts can only be unbanned via FTP." );
}
else
{
if( PlayerInfo[MAX_PLAYERS][pBanned] >= 0)
{
PlayerInfo[MAX_PLAYERS][pBanned] = 0;
PlayerInfo[MAX_PLAYERS][pWarns] = 0;
PlayerInfo[MAX_PLAYERS][pDisabled] = 0;
RemoveBan(PlayerInfo[MAX_PLAYERS][pIP]);
print("OnPlayerOfflineLogin: Saving variables to file");
OnPlayerOfflineSave(params);
print("OnPlayerOfflineLogin: Variables saved properly");
format(string, 128, "AdmCmd: %s (IP:%s) was unbanned by %s.", params, PlayerInfo[MAX_PLAYERS][pIP], GetPlayerNameEx(playerid));
ABroadCast(COLOR_LIGHTRED,string,2);
new year, month,day;
new query[120];
format(query,sizeof(query),"DELETE FROM `bans` WHERE `name` = '%s'",params);
mysql_query(query, [Your mysql databse name]);
getdate(year, month, day);
format(string, sizeof(string), "AdmCmd: %s (IP:%s) was unbanned by %s. (%d-%d-%d)", params, PlayerInfo[MAX_PLAYERS][pIP], GetPlayerNameEx(playerid),month,day,year);
Log("logs/ban.log", string);
print(string);
}
else
{
SendClientMessageEx( playerid, COLOR_WHITE, "Not a banned account!" );
}
}
}
else
{
SendClientMessageEx( playerid, COLOR_WHITE, "That account doesn't exist." );
}
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
}
return 1;
}
You were missing this.
PHP код:
new query[120];
format(query,sizeof(query),"DELETE FROM `bans` WHERE `name` = '%s'",params);
mysql_query(query, [Your mysql databse name]);
And yeah enter your db name after the query,
Re: Mysql Delete data... -
daghost111 - 29.11.2016
Working!Thank you!
Rep +