SA-MP Forums Archive
MySQL Register and Login 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: MySQL Register and Login problem (/showthread.php?tid=212042)



MySQL Register and Login problem - Sascha - 16.01.2011

Hi..
I changed my script to mysql but it doesn't work how it should...

OnPlayerCommandText:
pawn Код:
format(dat, sizeof(dat), "SELECT * FROM `User` WHERE `Name`='%s'", name);
    mysql_query(dat);
    mysql_store_result();
    if(!mysql_num_rows())
    {
        ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Registration", "Welcome to [HSA]Sgt's SA Heaven!\r\n\
        As your name is not registered in our Database yet, you\r\nhave to register before you can start playing.\r\n\
        Please enter the password you want to use below.\r\nIf you'd like to take another name click \"Quit\""
, "Continue", "Quit");
    }else{
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login", "Welcome Back to [HSA]Sgt's SA Heaven!\r\n\
        Your username is already registered in the HSA DataBase,\r\ntherefore please enter your password below\r\n\
        to start playering.\r\nIf this is not your account use\"Quit\" and take another name."
, "Login", "Quit");
    }
    mysql_free_result();
... if I enter, it always shows the login dialog -.-...

Login Dialog (part of):
pawn Код:
new dat[500], string[256], date[50], day, month, year, ip[40], tmp[50];
            GetPlayerName(playerid, name, sizeof(name));
            format(dat, sizeof(dat), "SELECT * From `User` WHERE `Name`='%s' AND `Password`='md5('%s')", name, inputtext);
            mysql_query(dat);
            mysql_store_result();
            if(mysql_num_rows())
            {
                mysql_get_field("Level", tmp);
                PlayerData[playerid][Level] = strval(tmp);
                mysql_get_field("Score", tmp);
                SetPlayerScore(playerid, strval(tmp));
                mysql_get_field("Money", tmp);
                SetPlayerMoney(playerid, strval(tmp));
                GetPlayerIp(playerid, ip, sizeof(ip));
                getdate(year, month, day);
                format(date, sizeof(date), "%d/%d/%d", day, year, month);
                format(dat, sizeof(dat), "UPDATE `User` SET `LoginDate`='%s', `LoginIP`='%s' (WHERE `Name=`='%s')", date, ip, name);
                mysql_query(dat);
I can always login, doesn't care whether the pass was wrong or not... and when i login it doesn't save the Level, etc. in the variables...

(gstyle's plugin)

EDIT:
I changed OnPlayerConnect to
pawn Код:
if(mysql_num_rows() >= 1){
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login", "Welcome Back to [HSA]Sgt's SA Heaven!\r\n\
        Your username is already registered in the HSA DataBase,\r\ntherefore please enter your password below\r\n\
        to start playering.\r\nIf this is not your account use\"Quit\" and take another name."
, "Login", "Quit");
    }else
    {
        ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Registration", "Welcome to [HSA]Sgt's SA Heaven!\r\n\
        As your name is not registered in our Database yet, you\r\nhave to register before you can start playing.\r\n\
        Please enter the password you want to use below.\r\nIf you'd like to take another name click \"Quit\""
, "Continue", "Quit");
    }
however now it always askes me to register -.-


Re: MySQL Register and Login problem - Anthonyx3' - 16.01.2011

pawn Код:
if(!mysql_num_rows())
    {
        //register
    }
    else
    {
        //login

    }
    mysql_free_result();
Try this one out


Re: MySQL Register and Login problem - hanzen - 16.01.2011

Show us your OnPlayerConnect() query.


Re: MySQL Register and Login problem - Sascha - 16.01.2011

Quote:
Originally Posted by hanzen
Посмотреть сообщение
Show us your OnPlayerConnect() query.
it's written in the first code line lol

format(dat, sizeof(dat), "SELECT * FROM `User` WHERE `Name`='%s'", name);

well I guess the probleme is no the connection...
in the mysql log it says:
CMySQLHandler::Connect() - Access denied for user 'sgtadmin_hsabot@'@'lizard.serverffs.com' (using password: YES) (Error ID: 1045)

however I'm entered this:
#define SQL_USER "sgtadmin_hsabot@sgt-site.tk"


Re: MySQL Register and Login problem - hanzen - 16.01.2011

That's most likely the reason, lol.


Re: MySQL Register and Login problem - Anthonyx3' - 16.01.2011

If you need help connecting your mysql i am willing to help, biqqbz@live.com is my msn, im pretty sure you messed up on it


Re: MySQL Register and Login problem - Typhome - 16.01.2011

Quote:
Originally Posted by Sascha
Посмотреть сообщение
it's written in the first code line lol

format(dat, sizeof(dat), "SELECT * FROM `User` WHERE `Name`='%s'", name);

well I guess the probleme is no the connection...
in the mysql log it says:
CMySQLHandler::Connect() - Access denied for user 'sgtadmin_hsabot@'@'lizard.serverffs.com' (using password: YES) (Error ID: 1045)

however I'm entered this:
#define SQL_USER "sgtadmin_hsabot@sgt-site.tk"
Use without @sgt-site.tk


Re: MySQL Register and Login problem - Sascha - 16.01.2011

well when I do that it automatically uses sgtadmin_hsabot@something.serverffs.com