PDA

View Full Version : OBan Aint WOrking [SQL]


ReD_HunTeR
18/01/2015, 12:17 PM
FIxed..

Ironboy
18/01/2015, 12:30 PM
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Banned`='1', `Reason`='%s', `BannedBy`='%s' WHERE `Username` = '%e'", reason, PlayerName(playerid), name);

xVIP3Rx
18/01/2015, 12:39 PM
CMD:oban(playerid, params[])
{
new name[25], reason[50];
if(!Logged[playerid]) return SendClientMessage(playerid, COLOR_RED, "You need to be logged in, to use this command");
if(IsSpawn[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You need to be spawned, to use this command");
if(sscanf(params, "s[25]s[50]", name, reason)) return SendClientMessage(playerid, COLOR_GREY, "Syntax: /oban [Name] [Reason]");
if(PlayerInfo[playerid][pAdminLevel] >= 5)
{
new query[128], string[128], time[10], date[10], h, m, s, y, mon, day;
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET Banned='1', Reason='%s', BannedBy='%s', WHERE Username = '%e'", reason, PlayerName(playerid), name);
mysql_tquery(mysql, query, "", "");
gettime(h, m, s);
getdate(y, mon, day);
format(time, sizeof(time), "%d:%d:%d", h, m, s);
format(date, sizeof(date), "%d/%d/%d", day, mon, y);
mysql_format(mysql, query, sizeof(query), "INSERT INTO `baninfo` (user_banned, user_banner, reason, ban_date, ban_time) VALUES ('%e', '%e', '%e', '%s', '%s')", name, PlayerName(playerid), reason, date, time);
mysql_tquery(mysql, query, "", "");
format(string, sizeof(string), "%s %s has offline banned %s [Reason: %s]",AdminLevelName(playerid),PlayerName(playerid),nam e,reason);
SendClientMessageToAll(COLOR_BLUE,string);
}
else SendClientMessage(playerid, COLOR_RED, "You are not authorized to use that command!");
return 1;
}


You didn't explain the problem, this code seems to work.
Does it ban, doesn't ban at all, or the player can get in after being banned, also show to part where it bans the player if he tried to join.

Also try to take a look at mysql_log at the server folder for any errors.

ReD_HunTeR
18/01/2015, 12:45 PM
FIxed..

Ironboy
18/01/2015, 12:49 PM
You didn't explain the problem, this code seems to work.
Does it ban, doesn't ban at all, or the player can get in after being banned, also show to part where it bans the player if he tried to join.

Also try to take a look at mysql_log at the server folder for any errors.

He put a coma ( , ) after BannedBy='%s' which will cause " error #1064: You have an error in your SQL syntax; "

OFFT: I'm not the person you're think, sorry.

Lordzy
18/01/2015, 12:57 PM
This isn't the actual problem, but nevertheless - you're escaping the player names which are already escaped by SA-MP, but not the ban reason.

ReD_HunTeR
18/01/2015, 02:32 PM
FIxed..

Ironboy
18/01/2015, 02:41 PM
[12:46:51] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[12:47:32] [DEBUG] mysql_format - connection: 1, len: 128, format: "UPDATE `players` SET Banned='1', Reason='%s', BannedBy='%s', WHERE `Username` = '%e'"
[12:47:32] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `players` SET Banned='1', Reason='', BannedBy='AYUB_KHAN'", callback: "(null)", format: "(null)"
[12:47:32] [DEBUG] mysql_format - connection: 1, len: 128, format: "INSERT INTO `baninfo` (user_banned, user_banner, reason, ban_date) VALUES ('%e', '%e', '%e', '%e')"
[12:47:32] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `baninfo` (user_banned, user_banner, reason, ban_dat", callback: "(null)", format: "(null)"
[12:47:32] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[12:47:32] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `Username` = '[CVT]ReD_HunTeR'' at line 1
[12:47:32] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError
[12:47:32] [DEBUG] CMySQLQuery::Execute[] - starting query execution



Why are you giving a coma after BannedBy? as i said above it is considered as an error.

Lordzy
18/01/2015, 02:43 PM
Check out IronBoy's reply, it has fixed your code.

ReD_HunTeR
18/01/2015, 02:49 PM
k thanx.. ill test it in 10 mins