mysql help
#1

I have this to make players login:
pawn Код:
stock LoginPlayer(playerid,password[])
{
    new query[300];
    mysql_real_escape_string(password,password);
    format(query,sizeof(query),"SELECT `score`,`kills`,`deaths`,`money`, `AdminLvl` FROM `jugadores` WHERE `nickname` = '%s' AND `pass` = sha1('%s') LIMIT 1",
    pInfo[playerid][nickname],password);
    mysql_query(query);
    if(!mysql_num_rows())
    {
        SendClientMessage(playerid,-1,""ERROR"Wrong Password");
    }
    else
    {
        new Query[600];
        format(Query, sizeof(Query), "SELECT * FROM `jugadores` WHERE `nickname` = '%s'", pInfo[playerid][nickname]);
        mysql_query(Query);
        mysql_store_result();
        mysql_fetch_row_format(Query, "|");
        sscanf(Query, "p<|>s[24]s[128]iiiiis[16]",pInfo[playerid][nickname],pInfo[playerid][pass],pInfo[playerid][score],
        pInfo[playerid][kills],pInfo[playerid][deaths],pInfo[playerid][money],pInfo[playerid][AdminLvl],pInfo[playerid][IP]);
        printf("%s",Query);
        GivePlayerMoney(playerid, pInfo[playerid][money]);
        SetPlayerScore(playerid, pInfo[playerid][score]);
        pInfo[playerid][LoggedIn] = true;
        mysql_free_result();
        SendClientMessage(playerid,0x00FF00FF,"You have been successfully logged in!");
        PlayerPlaySound(playerid, 1149, 0,0,0);
    }
    return 1;
}
The problem is you can log-in with any password and I also get this in the Debug:
Код:
[21:27:50] CMySQLHandler::FetchRow() - An error has occured. (Error ID: 2014, Commands out of sync; you can't run this command now)
Any help would be appreciated, thanks in advance!
Reply
#2

Use strcmp to check if the password is correct or incorrect.

Example:
pawn Код:
if(strcmp(string, PlayerData[playerid][Password], true) == 0) // correct
Reply
#3

Quote:
Originally Posted by Jack_Leslie
Посмотреть сообщение
Use strcmp to check if the password is correct or incorrect.

Example:
pawn Код:
if(strcmp(string, PlayerData[playerid][Password], true) == 0) // correct
Thanks, but I keep getting that error:
Код:
[21:27:50] CMySQLHandler::FetchRow() - An error has occured. (Error ID: 2014, Commands out of sync; you can't run this command now)
Which doesn't load the data.
Reply
#4

pawn Код:
mysql_fetch_row_format(Query, "|");
        sscanf(Query, "p<|>s[24]s[128]iiiiis[16]",pInfo[playerid][nickname],pInfo[playerid][pass],pInfo[playerid][score],
        pInfo[playerid][kills],pInfo[playerid][deaths],pInfo[playerid][money],pInfo[playerid][AdminLvl],pInfo[playerid][IP]);
        printf("%s",Query);
Why you fetch the query if you have sscanf already ? Try to delete that.
Reply
#5

Quote:
Originally Posted by RenovanZ
Посмотреть сообщение
pawn Код:
mysql_fetch_row_format(Query, "|");
        sscanf(Query, "p<|>s[24]s[128]iiiiis[16]",pInfo[playerid][nickname],pInfo[playerid][pass],pInfo[playerid][score],
        pInfo[playerid][kills],pInfo[playerid][deaths],pInfo[playerid][money],pInfo[playerid][AdminLvl],pInfo[playerid][IP]);
        printf("%s",Query);
Why you fetch the query if you have sscanf already ? Try to delete that.
Well now I get another error (in the console) and the data doesn't load.
Код:
[22:51:25] sscanf warning: String buffer overflow.
[22:51:25] SELECT * FROM `jugadores` WHERE `nickname` = 'Onfroi'
Reply
#6

Why do you do:
pawn Код:
sscanf(Query, "p<|>s[24]s[128]iiiiis[16]",pInfo[playerid][nickname],pInfo[playerid][pass],pInfo[playerid][score],
        pInfo[playerid][kills],pInfo[playerid][deaths],pInfo[playerid][money],pInfo[playerid][AdminLvl],pInfo[playerid][IP]);
I've never see that before. What are you attempting to do?
Reply
#7

Quote:
Originally Posted by Jack_Leslie
Посмотреть сообщение
Why do you do:
pawn Код:
sscanf(Query, "p<|>s[24]s[128]iiiiis[16]",pInfo[playerid][nickname],pInfo[playerid][pass],pInfo[playerid][score],
        pInfo[playerid][kills],pInfo[playerid][deaths],pInfo[playerid][money],pInfo[playerid][AdminLvl],pInfo[playerid][IP]);
I've never see that before. What are you attempting to do?
That's how you fetch data with sscanf, what do you mean?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)