SA-MP Forums Archive
how to check? - 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: how to check? (/showthread.php?tid=417002)



how to check? - speed258 - 19.02.2013

hi i wanna from mysql database check if player with specific ip is already registered in my database

Код HTML:
format(query,1024,"SELECT `Name1` FROM `ips` WHERE `IP` = '%s' LIMIT 1",PlayerName(playerid)); //check if name1 with that ip exist
			mysql_query(query);
			mysql_store_result();
			if(mysql_num_rows()== 0) // if name not exist - we insert
			{
			    format(query,256,"INSERT INTO `ips` (Name1, IP) VALUES ('%s','%s')",PlayerName(playerid), GetPlayerIpEx(playerid));
				mysql_query(query);
			}
			else if(mysql_num_rows()== 1) //if name1 with that ip exist we update our databese but this tame we update just name2
			{
			    format(query,512,"UPDATE `ips` SET `Name2` = '%s' WHERE (`IP` = '%s')",PlayerName(playerid), GetPlayerIpEx(playerid));
				mysql_query(query);
			}
			else if(mysql_num_rows()== 2) //but if name1 and name2 exist but player connect with third nick we kick him
			{
			    Kick(playerid);
   			}
so what iam doing wrong?


Re: how to check? - Roko_foko - 19.02.2013

I am not sure, but I think it there is error in the first line:
Quote:
pawn Код:
format(query,1024,"SELECT `Name1` FROM `ips` WHERE `IP` = '%s' LIMIT 1",PlayerName(playerid));
Shouldn't it be
pawn Код:
new IP[16+1];
GetPlayerIp(playerid, IP, sizeof(IP));
format(query,1024,"SELECT `Name1` FROM `ips` WHERE `IP` = '%s' LIMIT 1",IP);