[MySQL] All players saving the same stats.
#1

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
Reply
#2

Your query is wrong.

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

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

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.
Reply
#5

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

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

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?
Reply
#8

I fixed the error! Thanks for the assistance guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)