MYSQL Saving Issue
#1

Hello Community,

For some reason the script saves some accounts incorrect and some correct.
Sometimes the data is swapped 3-4 spots to the left in the database causing major errors.

Hopefully any of you can find the issue because im out of clue's and I am working on this issue for days now!

Database structure:
http://puu.sh/hzcWx/b4e90f4d04.png
http://puu.sh/hzcY0/33cdfedfea.png
http://puu.sh/hzcZj/1de349659f.png

Load system:
pawn Код:
LoadPlayerData(playerid)
{
    clearPlayerChat(playerid);
    new Data[2048],Field[258],idx;
    mysql_queryF("SELECT * FROM `Accounts` WHERE `Username` = '%s' LIMIT 1", GetName(playerid));
    mysql_store_result();
    if(mysql_num_rows() == 1){
        mysql_fetch_rowEx(Data);
        //print(Data);
        Field = strtuk( Data, idx, '|' );
        for(new s = 0; s < 121; s++)
        {
            switch(s)
            {
                case 0: Player[playerid][UserID] = strval(Field);
                case 2: strmid(Player[playerid][Password],Field,0,strlen(Field),129);
                case 3: strmid(Player[playerid][LastIP],Field,0,strlen(Field),26);
                case 4: Player[playerid][Adminlevel] = strval(Field);
                case 5: Player[playerid][Money] = strval(Field);
                case 6: Player[playerid][RegTime] = strval(Field);
                case 7: Player[playerid][LastOn] = strval(Field);
                case 8: Player[playerid][Level] = strval(Field);
                case 9: Player[playerid][Gender] = strval(Field);
                case 10: Player[playerid][Age] = strval(Field);
                case 11: Player[playerid][Health] = floatstr(Field);
                case 12: Player[playerid][Armour] = floatstr(Field);
                case 13: Player[playerid][Skin] = strval(Field);
                case 14: strmid(Player[playerid][Country],Field,0,strlen(Field),255);
                case 15: Player[playerid][Test] = strval(Field);
                case 16: Player[playerid][Faction] = strval(Field);
                case 17: Player[playerid][FactionRank] = strval(Field);
                case 18: strmid(Player[playerid][FactionRankName],Field,0,strlen(Field),255);
                case 19: Player[playerid][PrisonSelect] = strval(Field);
                case 20: Player[playerid][PrisonTime] = strval(Field);
                case 21: Player[playerid][AdminPrisonCount] = strval(Field);
                case 22: Player[playerid][SecondsLoggedIn] = strval(Field);
                case 23: Player[playerid][PlayingHours] = strval(Field);
                case 24: Player[playerid][AdminCode] = strval(Field);
                case 25: Player[playerid][PhoneN] = strval(Field);
                case 26: Player[playerid][PhoneCredit] = strval(Field);
                case 27: Player[playerid][PhoneBook] = strval(Field);
                case 28: Player[playerid][House] = strval(Field);
                case 29: Player[playerid][Hotel] = strval(Field);
                case 30: Player[playerid][Hospitalized] = strval(Field);
                case 31: Player[playerid][OnDuty] = strval(Field);
                case 32: Player[playerid][DutyClothes] = strval(Field);
                case 33: Player[playerid][LastSkin] = strval(Field);
                case 34: Player[playerid][LastX] = floatstr(Field);
                case 35: Player[playerid][LastY] = floatstr(Field);
                case 36: Player[playerid][LastZ] = floatstr(Field);
                case 37: Player[playerid][LastA] = floatstr(Field);
                case 38: Player[playerid][LastInt] = strval(Field);
                case 39: Player[playerid][LastWorld] = strval(Field);
                case 40: Player[playerid][InFactionHQ] = strval(Field);
                case 41: Player[playerid][InHouse] = strval(Field);
                case 42: Player[playerid][Helper] = strval(Field);
                case 43: Player[playerid][Moderator] = strval(Field);
                case 44: strmid(Player[playerid][BankPincode],Field,0,strlen(Field),5);
                case 45: Player[playerid][BankNumber] = strval(Field);
                case 46: Player[playerid][BankMoney] = strval(Field);
                case 47: Player[playerid][ExperiencePoints] = strval(Field);
                case 48: Player[playerid][ExperiencePointsNeeded] = strval(Field);
                case 49: Player[playerid][Coins] = strval(Field);
                case 50: Player[playerid][WalkieTalkie] = strval(Field);
                case 51: Player[playerid][WalkieFrequency] = strval(Field);
                case 52: Player[playerid][HasMask] = strval(Field);
                case 53: Player[playerid][Banned] = strval(Field);
                case 54: Player[playerid][Bans] = strval(Field);
                case 55: Player[playerid][Kicks] = strval(Field);
                case 56: Player[playerid][WeaponSlot0] = strval(Field);
                case 57: Player[playerid][WeaponSlot1] = strval(Field);
                case 58: Player[playerid][WeaponSlot2] = strval(Field);
                case 59: Player[playerid][WeaponSlot3] = strval(Field);
                case 60: Player[playerid][WeaponSlot4] = strval(Field);
                case 61: Player[playerid][WeaponSlot5] = strval(Field);
                case 62: Player[playerid][WeaponSlot6] = strval(Field);
                case 63: Player[playerid][WeaponSlot7] = strval(Field);
                case 64: Player[playerid][WeaponSlot8] = strval(Field);
                case 65: Player[playerid][WeaponSlot9] = strval(Field);
                case 66: Player[playerid][WeaponSlot10] = strval(Field);
                case 67: Player[playerid][WeaponSlot11] = strval(Field);
                case 68: Player[playerid][WeaponSlot0Ammo] = strval(Field);
                case 69: Player[playerid][WeaponSlot1Ammo] = strval(Field);
                case 70: Player[playerid][WeaponSlot2Ammo] = strval(Field);
                case 71: Player[playerid][WeaponSlot3Ammo] = strval(Field);
                case 72: Player[playerid][WeaponSlot4Ammo] = strval(Field);
                case 73: Player[playerid][WeaponSlot5Ammo] = strval(Field);
                case 74: Player[playerid][WeaponSlot6Ammo] = strval(Field);
                case 75: Player[playerid][WeaponSlot7Ammo] = strval(Field);
                case 76: Player[playerid][WeaponSlot8Ammo] = strval(Field);
                case 77: Player[playerid][WeaponSlot9Ammo] = strval(Field);
                case 78: Player[playerid][WeaponSlot10Ammo] = strval(Field);
                case 79: Player[playerid][WeaponSlot11Ammo] = strval(Field);
                case 80: Player[playerid][DutyWeaponSlot0] = strval(Field);
                case 81: Player[playerid][DutyWeaponSlot1] = strval(Field);
                case 82: Player[playerid][DutyWeaponSlot2] = strval(Field);
                case 83: Player[playerid][DutyWeaponSlot3] = strval(Field);
                case 84: Player[playerid][DutyWeaponSlot4] = strval(Field);
                case 85: Player[playerid][DutyWeaponSlot5] = strval(Field);
                case 86: Player[playerid][DutyWeaponSlot6] = strval(Field);
                case 87: Player[playerid][DutyWeaponSlot7] = strval(Field);
                case 88: Player[playerid][DutyWeaponSlot8] = strval(Field);
                case 89: Player[playerid][DutyWeaponSlot9] = strval(Field);
                case 90: Player[playerid][DutyWeaponSlot10] = strval(Field);
                case 91: Player[playerid][DutyWeaponSlot11] = strval(Field);
                case 92: Player[playerid][DutyWeaponSlot0Ammo] = strval(Field);
                case 93: Player[playerid][DutyWeaponSlot1Ammo] = strval(Field);
                case 94: Player[playerid][DutyWeaponSlot2Ammo] = strval(Field);
                case 95: Player[playerid][DutyWeaponSlot3Ammo] = strval(Field);
                case 96: Player[playerid][DutyWeaponSlot4Ammo] = strval(Field);
                case 97: Player[playerid][DutyWeaponSlot5Ammo] = strval(Field);
                case 98: Player[playerid][DutyWeaponSlot6Ammo] = strval(Field);
                case 99: Player[playerid][DutyWeaponSlot7Ammo] = strval(Field);
                case 100: Player[playerid][DutyWeaponSlot8Ammo] = strval(Field);
                case 101: Player[playerid][DutyWeaponSlot9Ammo] = strval(Field);
                case 102: Player[playerid][DutyWeaponSlot10Ammo] = strval(Field);
                case 103: Player[playerid][DutyWeaponSlot11Ammo] = strval(Field);
                case 104: Player[playerid][AntiCheatExemption] = strval(Field);
                case 105: strmid(Player[playerid][Email],Field,0,strlen(Field),128);
                case 106: Player[playerid][Warns] = strval(Field);
                case 107: Player[playerid][Badge] = strval(Field);
                case 110: strmid(Player[playerid][SecretWord],Field,0,strlen(Field),128);
                case 111: Player[playerid][DisconnectReason] = strval(Field);
                case 112: Player[playerid][Business] = strval(Field);
                case 113: Player[playerid][FightStyle] = strval(Field);
                case 119: Player[playerid][SpawnedPersonalCar] = strval(Field);
            }
            Field = strtuk( Data, idx, '|' );
        }
        clearPlayerChat(playerid);
        SPD(playerid, DIALOG_AUTHENTICATION);
        TextDrawHideForPlayer(playerid, Text:LoadingTD);
    }else if(mysql_num_rows() == 0){
        clearPlayerChat(playerid);
        new playernamesplit[3][MAX_PLAYER_NAME], Name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, Name, sizeof(Name));
        split2(Name, playernamesplit, '_');

        if (!strlen(playernamesplit[0]) || !strlen(playernamesplit[1]))
        {
            KickWithMessage(playerid, COLOR_WHITE, "Unfortunately, your name is not in the proper format! Please use the format of "#COL_EMB_LIGHTBLUE"\"Firstname_Lastname\""#COL_EMB_WHITE".");
        }
        else
        {
            SPD(playerid, DIALOG_REGISTER);
            TextDrawHideForPlayer(playerid, Text:LoadingTD);
        }
    }
    mysql_free_result();
}
Save system:
pawn Код:
stock SavePlayerData(playerid)
{
    if(Authenticated[playerid] == 1)
    {
        new
            query[2000],
            Float: pHealth,
            Float: pArmour;

        GetPlayerHealth(playerid, pHealth);
        GetPlayerArmour(playerid, pArmour);

        format(query, sizeof(query), "UPDATE `Accounts` SET `Adminlevel` = %d, `Money` = %d, `Level` = %d, `LastOn` = %d, `Health` = %f, `Armour` = %f, `Skin` = %d, `Gender` = %d, `LastIP` = '%s', `Age` = %d, `Country` = '%s', `Test` = %d, `Faction` = %d, `FactionRank` = %d, `FactionRankName` = '%s', ",
            Player[playerid][Adminlevel],
            GetPlayerCash(playerid),
            Player[playerid][Level],
            Player[playerid][LastOn],
            pHealth,
            pArmour,
            Player[playerid][Skin],
            Player[playerid][Gender],
            PlayerConnectedIP[playerid],
            Player[playerid][Age],
            Player[playerid][Country],
            Player[playerid][Test],
            Player[playerid][Faction],
            Player[playerid][FactionRank],
            Player[playerid][FactionRankName]);

        format(query, sizeof(query), "%s`PrisonSelect` = %d, `PrisonTime` = %d, `AdminPrisonCount` = %d, `SecondsLoggedIn` = %d, `PlayingHours` = %d, `AdminCode` = %d, `PhoneN` = %d, `PhoneCredit` = %d, `PhoneBook` = %d, `House` = %d, `Hotel` = %d, `Hospitalized` = %d, ",
            query,
            Player[playerid][PrisonSelect],
            Player[playerid][PrisonTime],
            Player[playerid][AdminPrisonCount],
            Player[playerid][SecondsLoggedIn],
            Player[playerid][PlayingHours],
            Player[playerid][AdminCode],
            Player[playerid][PhoneN],
            Player[playerid][PhoneCredit],
            Player[playerid][PhoneBook],
            Player[playerid][House],
            Player[playerid][Hotel],
            Player[playerid][Hospitalized]);

        format(query, sizeof(query), "%s`OnDuty` = %d, `DutyClothes` = %d, `LastSkin` = %d, `LastX` = %f, `LastY` = %f, `LastZ` = %f, `LastA` = %f, `LastInt` = %d, `LastWorld` = %d, `InFactionHQ` = %d, `InHouse` = %d, ",
            query,
            0,
            Player[playerid][DutyClothes],
            Player[playerid][LastSkin],
            Player[playerid][LastX],
            Player[playerid][LastY],
            Player[playerid][LastZ],
            Player[playerid][LastA],
            Player[playerid][LastInt],
            Player[playerid][LastWorld],
            Player[playerid][InFactionHQ],
            Player[playerid][InHouse]);

        format(query, sizeof(query), "%s`Helper` = %d, `Moderator` = %d, `BankPincode` = '%s', `BankNumber` = %d, `BankMoney` = %d, `ExperiencePoints` = %d, `ExperiencePointsNeeded` = %d, `Coins` = %d, `WalkieTalkie` = %d, `WalkieFrequency` = %d, ",
            query,
            Player[playerid][Helper],
            Player[playerid][Moderator],
            Player[playerid][BankPincode],
            Player[playerid][BankNumber],
            Player[playerid][BankMoney],
            Player[playerid][ExperiencePoints],
            Player[playerid][ExperiencePointsNeeded],
            Player[playerid][Coins],
            Player[playerid][WalkieTalkie],
            Player[playerid][WalkieFrequency]);

        format(query, sizeof(query), "%s`WeaponSlot0` = %d, `WeaponSlot1` = %d, `WeaponSlot2` = %d, `WeaponSlot3` = %d, `WeaponSlot4` = %d, `WeaponSlot5` = %d, `WeaponSlot6` = %d, `WeaponSlot7` = %d, `WeaponSlot8` = %d, `WeaponSlot9` = %d, `WeaponSlot10` = %d, `WeaponSlot11` = %d, ",
            query,
            Player[playerid][WeaponSlot0],
            Player[playerid][WeaponSlot1],
            Player[playerid][WeaponSlot2],
            Player[playerid][WeaponSlot3],
            Player[playerid][WeaponSlot4],
            Player[playerid][WeaponSlot5],
            Player[playerid][WeaponSlot6],
            Player[playerid][WeaponSlot7],
            Player[playerid][WeaponSlot8],
            Player[playerid][WeaponSlot9],
            Player[playerid][WeaponSlot10],
            Player[playerid][WeaponSlot11]);

        format(query, sizeof(query), "%s`WeaponSlot0Ammo` = %d, `WeaponSlot1Ammo` = %d, `WeaponSlot2Ammo` = %d, `WeaponSlot3Ammo` = %d, `WeaponSlot4Ammo` = %d, `WeaponSlot5Ammo` = %d, `WeaponSlot6Ammo` = %d, `WeaponSlot7Ammo` = %d, `WeaponSlot8Ammo` = %d, `WeaponSlot9Ammo` = %d, `WeaponSlot10Ammo` = %d, `WeaponSlot11Ammo` = %d WHERE `Username` = '%s'",
            query,
            Player[playerid][WeaponSlot0Ammo],
            Player[playerid][WeaponSlot1Ammo],
            Player[playerid][WeaponSlot2Ammo],
            Player[playerid][WeaponSlot3Ammo],
            Player[playerid][WeaponSlot4Ammo],
            Player[playerid][WeaponSlot5Ammo],
            Player[playerid][WeaponSlot6Ammo],
            Player[playerid][WeaponSlot7Ammo],
            Player[playerid][WeaponSlot8Ammo],
            Player[playerid][WeaponSlot9Ammo],
            Player[playerid][WeaponSlot10Ammo],
            Player[playerid][WeaponSlot11Ammo],
            GetName(playerid));

        mysql_query(query);

        format(query, sizeof(query), "UPDATE `Accounts` SET `DutyWeaponSlot0` = %d, `DutyWeaponSlot1` = %d, `DutyWeaponSlot2` = %d, `DutyWeaponSlot3` = %d, `DutyWeaponSlot4` = %d, `DutyWeaponSlot5` = %d, `DutyWeaponSlot6` = %d, `DutyWeaponSlot7` = %d, `DutyWeaponSlot8` = %d, `DutyWeaponSlot9` = %d, `DutyWeaponSlot10` = %d, `DutyWeaponSlot11` = %d, ",
            Player[playerid][DutyWeaponSlot0],
            Player[playerid][DutyWeaponSlot1],
            Player[playerid][DutyWeaponSlot2],
            Player[playerid][DutyWeaponSlot3],
            Player[playerid][DutyWeaponSlot4],
            Player[playerid][DutyWeaponSlot5],
            Player[playerid][DutyWeaponSlot6],
            Player[playerid][DutyWeaponSlot7],
            Player[playerid][DutyWeaponSlot8],
            Player[playerid][DutyWeaponSlot9],
            Player[playerid][DutyWeaponSlot10],
            Player[playerid][DutyWeaponSlot11]);

        format(query, sizeof(query), "%s`DutyWeaponSlot0Ammo` = %d, `DutyWeaponSlot1Ammo` = %d, `DutyWeaponSlot2Ammo` = %d, `DutyWeaponSlot3Ammo` = %d, `DutyWeaponSlot4Ammo` = %d, `DutyWeaponSlot5Ammo` = %d, `DutyWeaponSlot6Ammo` = %d, `DutyWeaponSlot7Ammo` = %d, `DutyWeaponSlot8Ammo` = %d, `DutyWeaponSlot9Ammo` = %d, `DutyWeaponSlot10Ammo` = %d, `DutyWeaponSlot11Ammo` = %d, ",
            query,
            Player[playerid][DutyWeaponSlot0Ammo],
            Player[playerid][DutyWeaponSlot1Ammo],
            Player[playerid][DutyWeaponSlot2Ammo],
            Player[playerid][DutyWeaponSlot3Ammo],
            Player[playerid][DutyWeaponSlot4Ammo],
            Player[playerid][DutyWeaponSlot5Ammo],
            Player[playerid][DutyWeaponSlot6Ammo],
            Player[playerid][DutyWeaponSlot7Ammo],
            Player[playerid][DutyWeaponSlot8Ammo],
            Player[playerid][DutyWeaponSlot9Ammo],
            Player[playerid][DutyWeaponSlot10Ammo],
            Player[playerid][DutyWeaponSlot11Ammo]);

        format(query, sizeof(query), "%s`AntiCheatExemption` = %d, `Bans` = %d, `Kicks` = %d, `LastOnDate` = '%s', `Banned` = %d, `Email` = '%s', `Warns` = %d, `Badge` = %d, `Offline` = %d, `SecretWord` = '%s', `DisconnectReason` = %d, `Business` = %d, `FightStyle` = %d, `SpawnedPersonalCar` = %d WHERE `Username` = '%s'",
            query,
            Player[playerid][AntiCheatExemption],
            Player[playerid][Bans],
            Player[playerid][Kicks],
            date(gettime()+3600, 1),
            Player[playerid][Banned],
            Player[playerid][Email],
            Player[playerid][Warns],
            Player[playerid][Badge],
            Player[playerid][Offline],
            Player[playerid][SecretWord],
            Player[playerid][DisconnectReason],
            Player[playerid][Business],
            Player[playerid][FightStyle],
            Player[playerid][SpawnedPersonalCar],
            GetName(playerid));

        mysql_query(query);
    }
    return 1;
}
Reply
#2

Bump
Reply
#3

Use threaded queries and for the love of god normalize your database. If you need to add a number to a column name you are doing databases wrong.
Reply


Forum Jump:


Users browsing this thread: