PDA

View Full Version : Mysql checking if an account exists problem


arko123
13/08/2013, 12:10 PM
What's wrong with this?

forward CheckPlayer(playerid);

public CheckPlayer(playerid)
{
new string[256], PlayerName[MAX_PLAYER_NAME], EscapedName[MAX_PLAYER_NAME];
mysql_store_result();
GetPlayerName(playerid,PlayerName, sizeof(PlayerName));
mysql_real_escape_string(PlayerName, EscapedName);
format(string, sizeof(string), "SELECT * from accounts WHERE Username='%s' LIMIT 1", EscapedName);
mysql_query(string);
if(mysql_num_rows() != 0) {
ShowPlayerDialog(playerid, Dialog_Login, DIALOG_STYLE_INPUT, "Notice", "This account is registered, if you are the account owner please login", "Login", "Close");
} else {
ShowPlayerDialog(playerid, Dialog_Register, DIALOG_STYLE_INPUT, "Notice", "This account is not registered, if you wish to register this account please enter a password below", "Register", "Close");
}
mysql_free_result();
return 1;
}

XcorelloX
13/08/2013, 12:45 PM
forward CheckPlayer(playerid);

public CheckPlayer(playerid)
{
new string[256], PlayerName[MAX_PLAYER_NAME], EscapedName[MAX_PLAYER_NAME];
GetPlayerName(playerid,PlayerName, sizeof(PlayerName));
mysql_real_escape_string(PlayerName, EscapedName);
format(string, sizeof(string), "SELECT * from accounts WHERE Username='%s' LIMIT 1", EscapedName);
mysql_query(string);
mysql_store_result();
if(mysql_num_rows() != 0) {
ShowPlayerDialog(playerid, Dialog_Login, DIALOG_STYLE_INPUT, "Notice", "This account is registered, if you are the account owner please login", "Login", "Close");
} else {
ShowPlayerDialog(playerid, Dialog_Register, DIALOG_STYLE_INPUT, "Notice", "This account is not registered, if you wish to register this account please enter a password below", "Register", "Close");
}
mysql_free_result();
return 1;
}

arko123
13/08/2013, 12:50 PM
Cheers

Vince
13/08/2013, 12:51 PM
// Code


Actually say what you changed and why, instead of just posting some code. How is he supposed to learn if he doesn't/didn't know what he did wrong?

XcorelloX
13/08/2013, 01:06 PM
Actually say what you changed and why, instead of just posting some code. How is he supposed to learn if he doesn't/didn't know what he did wrong?

He is supposed to learn by reading the code, comparing and realizing for himself. They don't give you questions in school and an answer book to look at. He's not stupid, he can inspect it himself without me writing a detailed explanation to what he did wrong.

Simply by reading my code, he can see that I had moved the mysql_store_result(); below the query, whereas in his code it was above the query. Therefore, by him noticing that he will remember that mysql_store_result(); comes after the query and not before.