27.05.2010, 02:23
How would i check if a username exists in MySQL?
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; }
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; } |
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; }
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) |
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; }
format(string,sizeof(string),"SELECT * FROM Accounts WHERE `username` '%s'",GetName(playerid));