Mysql Select issue
#1

hello,

I have a filterscript, whitelist sort of way, I have a database table structured this way:

PRIMARY KEY - VARCHAR(32) - VARCHAR(32)
ID (int 11) - Player - IP

when a player joins the server, the filterscript must check the table if the playername is in there, if it's not, kick the player;

the issue is that, the table is empty with no data, but when player joins with whatever name, it doesn't kick him and says that he is on the database.

Here is some code :
Код:
CheckState(playerid)
{
	
	if(Enabled) //
	{
		CheckMySQL();
		new string[128], plrIP[16];
	    GetPlayerIp(playerid, plrIP, sizeof(plrIP));


		format(string, sizeof(string), "SELECT * FROM acplayers WHERE Player = '%s'", GetName(playerid));
		mysql_query(string);
		mysql_store_result();
		
		if(!mysql_num_rows()) // Kick him + Telling him to be in whitelist
		{
			// this line should be triggered cuz there is no player on table for now.. but it doesn't. it goes to the else statement.
		    Connected[playerid] = false;
		    KickInTime(playerid, 1);
	 	}
		else 
		{
		    mysql_free_result();
			// check if whitelisted ip is ok
			format(string, sizeof(string), "SELECT * FROM acplayers WHERE Player = '%s' AND IP = '%s'", GetName(playerid), plrIP);
			mysql_query(string);
			mysql_store_result();
			if(!mysql_num_rows()) // Kick him if not.
			{
			    Connected[playerid] = false;
		    	KickInTime(playerid, 2);
	 		}
	 		else
	 		{
				new row[128];
				new field[4][64];
				mysql_fetch_row_format(row, "|");
				explode(row, field, "|");
				mysql_free_result();
				format(ACPlayers[playerid][PlayerIP], 16, "%s", field[1]); // Address IPs
    			SendClientMessage(playerid, -1, ACPlayers[playerid][PlayerIP]); // This prints nothing "";
			}
		}
		mysql_free_result();
	}
    
}
thank you
Reply
#2

More details : mysql_log says I can't connect to root@localhost

database info:
127.0.0.1 root root dbnameexp

Any idea why it's not leting me in my localhost db? // I'm able to connect to it on a little application in C/C++ with working queries.
Reply
#3

sorry for reposting, edit didn't wanna work ..

mysql_log:

[21:05:29] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "root", password: "****", port: 3306, autoreconnect: true
[21:05:29] [DEBUG] CMySQLHandle::Create - creating new connection..
[21:05:29] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[21:05:29] [DEBUG] CMySQLHandle::Create - connection created with ID = 1
[21:05:29] [DEBUG] mysql_errno - connection: 1
[21:05:29] [DEBUG] mysql_query - connection: 1, query: "INSERT INTO `acplayers` (Player, IP) VALUES('TEST', '1243')"
[21:05:29] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[21:05:29] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[21:05:29] [DEBUG] CMySQLConnection:isconnect - connection was closed
[21:05:29] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
Reply
#4

SOLVED!

I was doing mysql_connect(host, user, pass, name) when it should have been mysql_connect(host, user, name, pass);
i was following standard format but i didn't know better.. thanks anyway
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)