PDA

View Full Version : [MySQL] All players saving the same stats.


ounce
30/07/2015, 05:57 PM
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.


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

]Rafaellos[
30/07/2015, 06:04 PM
Your query is wrong.

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

gurmani11
30/07/2015, 06:05 PM
format(query, sizeof(query), "UPDATE `users` SET `gunpackages` = '%s', `packageammo` = '%s' WHERE `ID`='%d' Limit 1",packages,ammo,playerinfo[playerid][id]);

dominik523
30/07/2015, 06:06 PM
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.

ounce
30/07/2015, 06:08 PM
Thanks for the fast replies! I'm trying both and getting back to you!

ounce
30/07/2015, 06:37 PM
Uh well guys, the packages doesn't save at all now? :/

Jacket
30/07/2015, 06:45 PM
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?

ounce
30/07/2015, 06:54 PM
I fixed the error! Thanks for the assistance guys!