MySQL help checking if user 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)
+--- Thread: MySQL help checking if user exists (
/showthread.php?tid=413661)
MySQL help checking if user exists -
wilko1995 - 06.02.2013
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
Re: MySQL help checking if user exists -
3ventic - 06.02.2013
replace `%s` with '%s' inside the query format. Single quotes are used for strings, apostrophes are used for table and column names.