MySQL Register and Login problem
#1

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 -.-
Reply
#2

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

    }
    mysql_free_result();
Try this one out
Reply
#3

Show us your OnPlayerConnect() query.
Reply
#4

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"
Reply
#5

That's most likely the reason, lol.
Reply
#6

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
Reply
#7

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
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)