MySQL help checking if user exists
#1

Hello,

I need to check if the user exists, and if he does goes to login dialog, and if not, goes to register. here is the code i have already:

Код:
public OnPlayerConnect(playerid)
{
	PInfo[playerid][Level] = 0;
	new Name[MAX_PLAYER_NAME], Str[128],str[128];
	GetPlayerName(playerid, Name, sizeof(Name));
	format(str, sizeof(str), "SELECT * FROM `player` WHERE `username` = `%s`", Name);
	mysql_query(str);
	mysql_store_result();
	new rows = mysql_num_rows();
    if(!rows)
 	{
        format(Str, sizeof(Str), "Your account name, \"%s\", is not found\r\n Please register to continue", Name);
        ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "REGISTER", Str, "REGISTER", "LEAVE");
        return 1;
 	}
	if(rows == 1)
	{
	    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "LOGIN", "You are registered\r\n Enter your password to continue", "LOGIN", "LEAVE");
	    return 1;
	}
	
    mysql_free_result();

	return 1;
}
Thanks
Reply
#2

replace `%s` with '%s' inside the query format. Single quotes are used for strings, apostrophes are used for table and column names.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)