SA-MP Forums Archive
[MYSQL] Check if username exists? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [MYSQL] Check if username exists? (/showthread.php?tid=150625)



[MYSQL] Check if username exists? - coole210 - 27.05.2010

How would i check if a username exists in MySQL?


Re: [MYSQL] Check if username exists? - lolumadd - 27.05.2010

Код:
new string[128];
format(string, sizeof(string), "SELECT `something` FROM `table` WHERE `name` = '%s'", Name);
mysql_query(string);
if(mysql_num_rows() > 0)
{
//account exists
return 1;
}
else
{
//doesnt exist
return 0;
}



Re: [MYSQL] Check if username exists? - coole210 - 27.05.2010

alright thanks


Re: [MYSQL] Check if username exists? - Kyosaur - 27.05.2010

Quote:
Originally Posted by lolumadd
Код:
new string[128];
format(string, sizeof(string), "SELECT `something` FROM `table` WHERE `name` = '%s'", Name);
mysql_query(string);
if(mysql_num_rows() > 0)
{
//account exists
return 1;
}
else
{
//doesnt exist
return 0;
}
You forgot to store the result ?


Re: [MYSQL] Check if username exists? - coole210 - 27.05.2010

What do you mean? O.o


Re: [MYSQL] Check if username exists? - lolumadd - 27.05.2010

Oh yeah. Sorry.
To my code add:
mysql_store_result() after mysql_query

And after the last bracket add:
mysql_free_result()


Re: [MYSQL] Check if username exists? - coole210 - 30.05.2010

What?


Re: [MYSQL] Check if username exists? - coole210 - 30.05.2010

I need help with this now.. doesn't seem to work and i added a username called "Coole" in database

Код:
public OnPlayerConnect(playerid)
{
	new string[128];
 	format(string,sizeof(string),"SELECT * FROM `users` WHERE `Name` = '%s'",GetName(playerid));
	mysql_query(string,Connection);
	mysql_store_result(Connection);
	if(mysql_num_rows(Connection) > 0)
	{
	  ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Login","Enter your password below","Login","Exit");
	}
 	else
	{
	  ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Register","Enter your password below","Register","Exit");
	}
	mysql_free_result(Connection);
	return 1;
}



Re: [MYSQL] Check if username exists? - coole210 - 31.05.2010

bump..

I am using 000webhost's MySQL feature if that tells you anything (i cant get the mysql to work on wamp)


Re: [MYSQL] Check if username exists? - [HiC]TheKiller - 31.05.2010

1. Make sure it connects to the server.
2. Make sure the player name variable is Name.
3. Make sure the table name is correct.




Re: [MYSQL] Check if username exists? - coole210 - 31.05.2010

I made sure of everything, I know it connects (cuz of printf), I know the table name is correct, i know i added a field called "Coole" and i even tried LOWER(Name) and LOWER('%s')

.. Help?


Re: [MYSQL] Check if username exists? - lolumadd - 01.06.2010

mysql_store_result and mysql_free_result have 0 params. It is just mysql_store_result(); and mysql_free_result();


Re: [MYSQL] Check if username exists? - coole210 - 01.06.2010

I've tried that too. it still won't work lol


Re: [MYSQL] Check if username exists? - Antonio [G-RP] - 01.06.2010

Quote:
Originally Posted by Coole[AG
]
bump..

I am using 000webhost's MySQL feature if that tells you anything (i cant get the mysql to work on wamp)
I use 000webhost too


Re: [MYSQL] Check if username exists? - coole210 - 01.06.2010

Here's my current script:

Код:
public OnPlayerConnect(playerid)
{
	new string[128];
 	format(string,sizeof(string),"SELECT * FROM Accounts WHERE LOWER(Username) = LOWER('%s')",GetName(playerid));
	mysql_query(string);
	mysql_store_result();
	if(mysql_num_rows() > 0)
	{
	  ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Login","Enter your password below","Login","Exit");
	}
 	else
	{
	  ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Register","Enter your password below","Register","Exit");
	}
	mysql_free_result();
	return 1;
}
Screeny:






Re: [MYSQL] Check if username exists? - coole210 - 01.06.2010

bump


Re: [MYSQL] Check if username exists? - lolumadd - 01.06.2010

I dont what LOWER function does so..make it:
Код:
format(string,sizeof(string),"SELECT * FROM Accounts WHERE `username` '%s'",GetName(playerid));
(Also what mysql system thingy you use? It doesnt look like PHPmyadmin.)


Re: [MYSQL] Check if username exists? - coole210 - 01.06.2010

It is PHPmyadmin

LOWER does this: COOLE would be coole and COole would be coole too so it loads LOWER username and LOWER Name of player


Re: [MYSQL] Check if username exists? - coole210 - 03.06.2010

bump