SQLite Ban System
#1

Code:
stock BanPlayer(playerid,AdministratorID,Reason[],Time)
{
	new String[150];
	format(String,150,"INSERT INTO `Bans` SET `BanUserName` = '%s',`BanUserIp` = '%s',`BanAdministratorName` = '%s',`BanReason` = '%s',`BanTime` = '%i'",UserName[playerid],UserIp[playerid],UserName[AdministratorID],Reason,Time);
	new DBResult:DatabaseResult = db_query(Database,String);
	db_free_result(DatabaseResult);
	Kick(playerid);
	return 1;
}
Code:
public OnPlayerConnect(playerid)
{
	GetPlayerName(playerid,UserName[playerid],30);
	GetPlayerIp(playerid,UserIp[playerid],30);
	BanPlayer(playerid,playerid,"Nothing",30324);
	new DBResult:DatabaseResult = db_query(Database,"SELECT * FROM `Bans` WHERE `BanUserReason` = 'Nothing`");
	if(db_num_rows(DatabaseResult))
	{
		new String[150];
		db_get_field_assoc(DatabaseResult,"BanUserName",String,30);
		printf(String);
		db_get_field_assoc(DatabaseResult,"BanUserIp",String,30);
		printf(String);
		db_get_field_assoc(DatabaseResult,"BanAdministratorName",String,30);
		printf(String);
		db_get_field_assoc(DatabaseResult,"BanUserReason",String,150);
		printf(String);
		db_get_field_assoc(DatabaseResult,"BanUserTime",String,30);
		printf(String);
	}
	db_free_result(DatabaseResult);
	return 1;
}
Code:
#include <a_samp>

#define MAXIMAL_PLAYERS 500

new DB:Database;
new UserName[MAXIMAL_PLAYERS][30];
new UserIp[MAXIMAL_PLAYERS][30];

public OnGameModeInit()
{
	Database = db_open("Server.db");
	new DBResult:DatabaseResult = db_query(Database,"CREATE TABLE IF NOT EXISTS `Bans` (`BanUserName` VARCHAR(30),`BanUserIp` VARCHAR(30),`BanAdministratorName` VARCHAR(30),`BanReason` VARCHAR(150),`BanTime` INT(30));");
	db_free_result(DatabaseResult);
	return 1;
}

public OnGameModeExit()
{
	db_close(Database);
	return 1;
}
Ban not added, why?
Reply
#2

print the query!!!!11!!!111
Reply
#3

What?
Reply
#4

Any help?
Reply
#5

Please help.
Reply
#6

Insert INTO have different syntax, this is UPDATE syntax

I've tried to make another system (i think more efficent than your) use this: http://pastebin.com/PjUt6tDF

Maybe you can improve your code by reading mine

#edit: important fixbug in IsBanned function
Reply
#7

Update? I want add ban no update ? How to update if not added?
Code:
INSERT INTO bans (time, reason, nickname) VALUES ('%d', '%s', '%s')
Eh, what thisis querys?
Reply
#8

INSERT INTO `Bans` SET `BanUserName` = '%s',`BanUserIp` = '%s',`BanAdministratorName` = '%s',`BanReason` = '%s',`BanTime` = '%i'


INSERT INTO `Bans`(BanUserName, BanUserIp, BanAdministratorName, BanReason, BanTime) VALUES ('%s', '%s', '%s', '%s', '%d')

This is your query fixed

--

INSERT INTO bans (time, reason, nickname) VALUES ('%d', '%s', '%s')

This is the correct query if you want to add into "bans" table
( time, reason, nickname ) -> where add values?
( values ) -> values
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)