[MySQL]: Somethings wrong with my login command?
#1

Hey, Heres my login command

pawn Код:
CMD:login(playerid, params[])
{
    new LogPass[24], pname[MAX_PLAYER_NAME], str[128];
    if(sscanf(params, "s", LogPass)) return SENDMSG(playerid, COLOR_GREENLIGHT, "[WR Usage]: /login [Password]");
    else if (strlen(LogPass) > 24) return ERRORMSG(playerid, "[WR Server]: The password is you typed is too long, try again");
    else if(IsLogged[playerid] == 1) return ERRORMSG(playerid, "[WR Server]: You're already logged in!");
    else
    {
      GetPlayerName(playerid, pname, sizeof(pname));
      format(query, sizeof(query), "SELECT * FROM users WHERE username = '%s'", PlayerName);
      mysql_query(query);
      mysql_store_result();
        if(mysql_num_rows() != 0)
        {
          format(query, sizeof(query), "SELECT password FROM users WHERE username = '%s'", PlayerName);
            mysql_query(query);
            mysql_store_result();
            if(strlen(query) == strlen(LogPass)) // Change to != if its all wrong on login
            {
        LoadStats(playerid);
            }
            else
            {
              format(str, sizeof(str), "logpass: %s, query: %s", strval(LogPass), strval(query));
                ERRORMSG(playerid, "[WR Server]: Login failed, try again");
            }
        }
        else
        {
            SENDMSG(playerid, COLOR_GREENLIGHT, "[WR Server]: This username is not found in the database, please use /register");
        }
    }
    return 1;
}
Theres something wrong with it, when i register (my register command works fine) and after i login it says its the wrong pass?
I cant see whats wrong, and im new to mysql so i dont know all the callbacks yet.
Reply
#2

Код:
mysql_store_result();
mysql_fetch_field("password",query);
if(strlen........
Reply
#3

like this?

pawn Код:
format(query, sizeof(query), "SELECT password FROM users WHERE username = '%s'", PlayerName);
            mysql_query(query);
            mysql_store_result();
            mysql_fetch_field("password",query);
            if(strlen(query) == strlen(LogPass)) // Change to != if its all wrong on login
            {
        LoadStats(playerid);
            }
What does it do, can you explain for me?
Reply
#4

yes^^
it fetches the query-result...
Reply
#5

It give me error:
Код:
error 035: argument type mismatch (argument 1)
the new line is the error line
Reply
#6

Lol what fail.

You check if password's length is same as length of query. Use some sense at least.
Reply
#7

it should be strval?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)