SA-MP Forums Archive
Trouble updating with BlueG's mysql R7 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Trouble updating with BlueG's mysql R7 (/showthread.php?tid=483277)



Trouble updating with BlueG's mysql R7 - 2KY - 25.12.2013

pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    if(is_logged[playerid] == true)
    {
        new
            mQuery[128];
           
        new
            pName[MAX_PLAYER_NAME];
           
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
       
        format(mQuery, sizeof(mQuery), "SELECT `id` from `accounts` WHERE `username` = '%s'", pName);
        mysql_function_query(myConnection, mQuery, true, "SavePlayerData", "i", playerid);
    }
    return 1;
}
pawn Code:
forward public SavePlayerData(playerid);
public SavePlayerData(playerid)
{
    new
        mQuery[500];
       
    new
            chr,
            cyr,
            cday,
            cmo,
            cmin,
            csec;

    getdate(cyr, cmo, cday);
    gettime(chr, cmin, csec);
       
    format(mQuery, sizeof(mQuery), "UPDATE `accounts` SET `Admin` = '%d', `CustomSkin` = '%d', `ActiveBuff` = '%d', `Killstreak` = '%d', `LastVisitedMonth` = '%d', `LastVisitedDay` = '%d', `LastVisitedYear` = '%d', `LastVisitedHour` = '%d', `LastVisitedMinute` = '%d'",
        PlayerInfo[playerid][Admin], PlayerInfo[playerid][CustomSkin], PlayerInfo[playerid][ActiveBuff],
        PlayerInfo[playerid][Killstreak], cmo, cday, cyr, chr, cmin
    );
    mysql_function_query(myConnection, mQuery, false, "", "");
   
    for(new i; i < 13; i++)
    {
        format(mQuery, sizeof(mQuery), "UPDATE `weapons` SET `weapon` = '%d', `ammo` = '%d' WHERE `id` = '%d' AND `index` = '%d'",
            PlayerInfo[playerid][SpawnWeapon][i], PlayerInfo[playerid][SpawnAmmo][i], PlayerInfo[playerid][pAccountID], i
        );
        mysql_function_query(myConnection, mQuery, false, "", "");
    }
    for(new i; i < 46; i++)
    {
        format(mQuery, sizeof(mQuery), "UPDATE `weaponkills` SET `weapon` = '%d', `kills` = '%d' WHERE `id` = '%d'",
            i, PlayerInfo[playerid][WeaponKills][i], PlayerInfo[playerid][pAccountID]
        );
        mysql_function_query(myConnection, mQuery, false, "", "");
    }
    is_logged[playerid] = false;
    return 1;
}
The first 'mQuery' works perfectly fine, and updates everything it should - the problem is located on my linked tables (`weaponkills`, `weapons`) Every time I change something in-game it never updates the database, and this is the function that actually updates the table so I was wondering if anyone could figure out what's wrong because I've been trying to figure this out for an hour or so and I'm completely clueless.


Re: Trouble updating with BlueG's mysql R7 - Zex Tan - 25.12.2013

Have you try debugging it? Post the code error and will check what's wrong with your queries.


Re: Trouble updating with BlueG's mysql R7 - 2KY - 25.12.2013

I've tried debugging it to my best ability. There are no mysql errors, mysql_debug is set to 1 and I've checked server log, there's nothing that's wrong with the query apparently but it's just not working. Everything inside of the callback runs, just doesn't update properly.


Re: Trouble updating with BlueG's mysql R7 - Kar - 25.12.2013

Sorry if this doesn't help but your query logicS seem ...

First query, there is no where. The query will update every account.

Third query, what?

FOR i TO 46 DO
UPDATE `weaponkills` SET `weapon` = '%d', `kills` = '%d' WHERE `id` = '%d'
endfor

UPDATE `weaponkills` SET `weapon` = '0', `kills` = '1000' WHERE `id` = 'Kar'
UPDATE `weaponkills` SET `weapon` = '1', `kills` = '1000' WHERE `id` = 'Kar'
UPDATE `weaponkills` SET `weapon` = '2', `kills` = '1000' WHERE `id` = 'Kar'
UPDATE `weaponkills` SET `weapon` = '3', `kills` = '1000' WHERE `id` = 'Kar'
...

Say what? it 'Looks right' but then again, it's just setting weapon to INDEX and kills to whatever that INDEX'd variable is to Kar.

Lastly...

pawn Code:
forward public SavePlayerData(playerid);
public SavePlayerData(playerid)
Say what?

Lastly again,

You haven't really said whats the problem. If it's that the weapon kills isn't being set for EACH weapon, I showed you the issue above.