SA-MP Forums Archive
[MySQL] All players saving the same stats. - 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: [MySQL] All players saving the same stats. (/showthread.php?tid=583735)



[MySQL] All players saving the same stats. - ounce - 30.07.2015

OK. So I'm trying to save some weapon packages here, but somehow all players on my database get's the same weapon packages whenever I disconnect from the server. Whenever I buy new packages, sell them, or delete them. Everyone get's the same stats as I had when I log out.


pawn Code:
public SavePackages(playerid)
{
        if(playerid != INVALID_PLAYER_ID && PlayerIsOn(playerid) && PlayerLogged(playerid))
        {
        new packages[128], ammo[128];
        format(packages, sizeof(packages), "%d|%d|%d|%d|%d|%d|%d|%d|%d|%d", PlayerInfo[playerid][pGunPackages][0], PlayerInfo[playerid][pGunPackages][1], PlayerInfo[playerid][pGunPackages][2], PlayerInfo[playerid][pGunPackages][3], PlayerInfo[playerid][pGunPackages][4], PlayerInfo[playerid][pGunPackages][5], PlayerInfo[playerid][pGunPackages][6], PlayerInfo[playerid][pGunPackages][7], PlayerInfo[playerid][pGunPackages][8], PlayerInfo[playerid][pGunPackages][9]);
        format(ammo, sizeof(ammo), "%d|%d|%d|%d|%d|%d|%d|%d|%d|%d", PlayerInfo[playerid][pPackageAmmo][0], PlayerInfo[playerid][pPackageAmmo][1], PlayerInfo[playerid][pPackageAmmo][2], PlayerInfo[playerid][pPackageAmmo][3], PlayerInfo[playerid][pPackageAmmo][4], PlayerInfo[playerid][pPackageAmmo][5], PlayerInfo[playerid][pPackageAmmo][6], PlayerInfo[playerid][pPackageAmmo][7], PlayerInfo[playerid][pPackageAmmo][8], PlayerInfo[playerid][pPackageAmmo][9]);
        format(query, sizeof(query), "UPDATE `users` SET `gunpackages` = '%s', `packageammo` = '%s'",packages,ammo);
        GetName(playerid);
        mysql_function_query(dbHandle, query, false, "", "");
        }
        ret



Re: [MySQL] All players saving the same stats. - ]Rafaellos[ - 30.07.2015

Your query is wrong.

pawn Code:
UPDATE `users` SET `gunpackages` = '%s', `packageammo` = '%s' WHERE `username field ?` = '%s'



Re: [MySQL] All players saving the same stats. - gurmani11 - 30.07.2015

PHP Code:
        format(querysizeof(query), "UPDATE `users` SET `gunpackages` = '%s', `packageammo` = '%s' WHERE `ID`='%d' Limit 1",packages,ammo,playerinfo[playerid][id]); 



Re: [MySQL] All players saving the same stats. - dominik523 - 30.07.2015

Try to print out packages and ammo strings before running the querry to make sure you actually have some package or ammo. Check for MySQL errors or warnings in your log file if everything is okay with the strings.

EDIT: Ahh, I haven't seen that you don't have "WHERE `ID`=&d" part in your query. That's why all the users have the same value all the time.


Re: [MySQL] All players saving the same stats. - ounce - 30.07.2015

Thanks for the fast replies! I'm trying both and getting back to you!


Re: [MySQL] All players saving the same stats. - ounce - 30.07.2015

Uh well guys, the packages doesn't save at all now? :/


Re: [MySQL] All players saving the same stats. - Jacket - 30.07.2015

Code:
format(query, sizeof(query), "UPDATE `users` SET `gunpackages` = '%s', `packageammo` = '%s'",packages,ammo);
This query internationally sets all of the data to each account in the database since there is no 'WHERE' statement. It's like saying you just want to give money to everybody, it doesn't matter to you.

I will help you with this. Do you have a pID enumerator? Do you have any callback to load gun packages?


Re: [MySQL] All players saving the same stats. - ounce - 30.07.2015

I fixed the error! Thanks for the assistance guys!