New MySQL Saving doesn't save player information
#1

hello guys everytime i logged in. all my account information is back to 0. but when i checked on phpmyadmin there is nothing wrong with saving. the problem is on loading. so i need your help to fix this problem.

Login Stock
pawn Код:
stock LoginPlayer(playerid, password[])
{
    new Query[256];
    format(Query,sizeof(Query),"SELECT * FROM `users` WHERE `Username` = '%s' AND `Password` = '%s'",PlayerName(playerid),password);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        format(Query, sizeof(Query), "SELECT * FROM `users` WHERE `Username` = '%s' ", PlayerName(playerid));
        mysql_query(Query);
        mysql_store_result();
        mysql_fetch_row_format(Query, "|");
        new fetchVal[100]; //A array to hold the data were going to get
        while(mysql_fetch_row_format(Query, "|"))
  {
            mysql_fetch_field_row(fetchVal, "Money");
            pInfo[playerid][pMoney] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "BankCash");
            pInfo[playerid][BankMoney] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Score");
            pInfo[playerid][Score] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Adminlevel");
            pInfo[playerid][Adminlevel] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Army");
            pInfo[playerid][Army] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "CIA");
            pInfo[playerid][Cia] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "RegularPlayer");
            pInfo[playerid][RegularPlayer] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Donator");
            pInfo[playerid][Donator] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "OttoOwner");
            pInfo[playerid][OttoOwner] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "TSkill");
            pInfo[playerid][TerroristSkill] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "RobSkill");
            pInfo[playerid][RobSkill] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "HasPackC4");
            pInfo[playerid][HasPackC4] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "HasPackRope");
            pInfo[playerid][HasPackRope] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "HasPackMoney");
            pInfo[playerid][HasPackMoney] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "SavedWantedLevel");
            pInfo[playerid][SavedWantedLevel] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "SavedJailTime");
            pInfo[playerid][SavedJailTime] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Coprank");
            pInfo[playerid][Coprank] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "HoursPlayed");
            pInfo[playerid][HoursPlayed] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "MinutesPlayed");
            pInfo[playerid][MinutesPlayed] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "SecondsPlayed");
            pInfo[playerid][SecondsPlayed] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Banned");
            pInfo[playerid][Banned] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Kills");
            pInfo[playerid][Kills] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "Deaths");
            pInfo[playerid][Deaths] = strval(fetchVal);

            mysql_fetch_field_row(fetchVal, "TotalHitFinished");
            pInfo[playerid][TotalHitFinished] = strval(fetchVal);

        }
        mysql_free_result();
        LoggedIn[playerid] = 1;
        GivePlayerMoney(playerid, pInfo[playerid][pMoney]);//sets player money to last money he has
        SetPlayerScore(playerid, pInfo[playerid][Score]);//sets player score's to last score he has
        return SendClientMessage(playerid,-1,"{FF0000}[INFO]: {FFFFFF}You have successfully logged in!");
        } else {
                ShowLoginScreen(playerid);
                SendClientMessage(playerid, -1,"{FF0000}[ERROR]: {FFFFFF}Incorrect Password. Please try again.");
        }
    //ShowLoginScreen(playerid);
    return 1;
}
My DIALOG_LOGIN
pawn Код:
/*Register/Login/Changepassword System*/
    if(dialogid == DIALOG_LOGIN)
    {
    if (response == 0)
    {
        SendClientMessage(playerid,COLOR_RED,"You must login before playing on this server.");
        ShowLoginScreen(playerid);
        return 1;
    }
    if (response == 1)
    {
        if (strlen(inputtext) == 0)
        {
            SendClientMessage(playerid,COLOR_RED,"Please enter your password for your account in the box below.");
            ShowLoginScreen(playerid);
            return 1;
        }
        new password[512];
        WP_Hash(password, sizeof(password),inputtext);
        LoginPlayer(playerid,password);
    }
Debug when i log in
pawn Код:
[10:31:13] >> mysql_store_result( Connection handle: 1 )

[10:31:13] CMySQLHandler::StoreResult() - Result was stored.

[10:31:13] >> mysql_num_rows( Connection handle: 1 )

[10:31:13] CMySQLHandler::NumRows() - Returned 1 row(s)

[10:31:13] >> mysql_free_result( Connection handle: 1 )

[10:31:13] CMySQLHandler::FreeResult() - Result was successfully free'd.

[10:31:18] >> mysql_query( Connection handle: 1 )

[10:31:18] CMySQLHandler::Query(SELECT * FROM `users` WHERE `Username` = '
[IEG]JakeS' AND `Password` = '5820F24A996444514B632AD22DC6FFBC69A1EF65C891A30C232EC369C5333E53D42EF5EE6BE9FDD1700B2ECB58D378FEDF527B311EDD15CC808B2A5D28488E99') - Successfully executed.

[10:31:18] >> mysql_store_result( Connection handle: 1 )

[10:31:18] CMySQLHandler::StoreResult() - Result was stored.

[10:31:18] >> mysql_num_rows( Connection handle: 1 )

[10:31:18] CMySQLHandler::NumRows() - Returned 1 row(s)

[10:31:18] >> mysql_query( Connection handle: 1 )

[10:31:18] CMySQLHandler::Query(SELECT * FROM `users` WHERE `Username` = '
[IEG]JakeS' ) - Successfully executed.

[10:31:18] >> mysql_store_result( Connection handle: 1 )

[10:31:18] CMySQLHandler::StoreResult() - Result was stored.

[10:31:18] >> mysql_fetch_row_format( Connection handle: 1 )

[10:31:18] CMySQLHandler::FetchRow() - Return: [IEG]JakeS|5820F24A996444514B632AD22DC6FFBC69A1EF65C891A30C232EC369C5333E53D42EF5EE6BE9FDD1700B2ECB58D378FEDF527B311EDD15CC808B2A5D28488E99|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|6|43|50|0|0|0|0

[10:31:18] >> mysql_fetch_row_format( Connection handle: 1 )

[10:31:18] >> mysql_free_result( Connection handle: 1 )

[10:31:18] CMySQLHandler::FreeResult() - Result was successfully free'
d.
Reply
#2

Not on topic, but i noticed you have a memory leak there. You don't free the first select query before executing the next one, and you should.

You also don't need two select queries, the first one holds the same data that the second one does.
Reply
#3

Thanks iggy1. got it fixed now!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)