SA-MP Forums Archive
Mysql checking if an account exists problem - 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 checking if an account exists problem (/showthread.php?tid=457810)



Mysql checking if an account exists problem - arko123 - 13.08.2013

What's wrong with this?
pawn Код:
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;
}



Re: Mysql checking if an account exists problem - XcorelloX - 13.08.2013

pawn Код:
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;
}



Re: Mysql checking if an account exists problem - arko123 - 13.08.2013

Cheers


Re: Mysql checking if an account exists problem - Vince - 13.08.2013

Quote:
Originally Posted by XcorelloX
Посмотреть сообщение
pawn Код:
// 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?


Re: Mysql checking if an account exists problem - XcorelloX - 13.08.2013

Quote:
Originally Posted by Vince
Посмотреть сообщение
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.