[MYSQL] Check if username exists?
#1

How would i check if a username exists in MySQL?
Reply
#2

Код:
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;
}
Reply
#3

alright thanks
Reply
#4

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 ?
Reply
#5

What do you mean? O.o
Reply
#6

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

And after the last bracket add:
mysql_free_result()
Reply
#7

What?
Reply
#8

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;
}
Reply
#9

bump..

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

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.

Reply
#11

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?
Reply
#12

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

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

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
Reply
#15

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:



Reply
#16

bump
Reply
#17

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.)
Reply
#18

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
Reply
#19

bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)