Problems saving weapons and ammunition in MySQL
#1

Could someone help me in this following code

Код:
public OnPlayerDisconnect(playerid, reason)
	UpdatePlayerData(playerid, reason);
	return 1;
}

UpdatePlayerData(playerid, reason)
{
	if (Player[playerid][IsLoggedIn] == false) return 0;

	// if the client crashed, it's not possible to get the player's position in OnPlayerDisconnect callback
	// so we will use the last saved position (in case of a player who registered and crashed/kicked, the position will be the default spawn point)
	if (reason == 1)
	{
		Player[playerid][Weapon] = GetPlayerWeapon(playerid);
		Player[playerid][Ammo] = GetPlayerAmmo(playerid);
	}
	
	new PlayersWeapons[300];
	mysql_format(g_SQL, PlayersWeapons, sizeof PlayersWeapons, "UPDATE `PlayersWeapons` SET `PlayerID` = %e, `WeaponID` = %i, `Ammo` = %i", Player[playerid][Name], Player[playerid][Weapon], Player[playerid][Ammo]);
	mysql_tquery(g_SQL, PlayersWeapons);
	
	return 1;
}
I can not save anything on PlayersWeapons

logs
Код:
[15:46:17] [DEBUG] mysql_format(1, 0x03C38C98, 300, "UPDATE `PlayersWeapons` SET `PlayerID` = %e, `WeaponID` = %i, `Ammo` = %i")
[15:46:17] [DEBUG] CHandle::EscapeString(this=0x995338, src='Jnn_Doug2')
[15:46:17] [DEBUG] CConnection::EscapeString(src='Jnn_Doug2', this=0x9a0d30, connection=0x9ae508)
[15:46:17] [DEBUG] CHandle::EscapeString - return value: true, escaped string: 'Jnn_Doug2'
[15:46:17] [DEBUG] mysql_format: return value: '83'
[15:46:17] [DEBUG] mysql_tquery(1, "UPDATE `PlayersWeapons` SET `PlayerID` = Jnn_Doug2, `WeaponID` = 24, `Ammo` = 32756", "", "")
[15:46:17] [DEBUG] CCallback::Create(amx=0x8a0f00, name='', format='', params=0x3c38c84, param_offset=5)
[15:46:17] [DEBUG] CHandle::Execute(this=0x995338, type=1, query=0x97ddd8)
[15:46:17] [DEBUG] CConnection::Execute(query=0x97ddd8, this=0x2a30020, connection=0x97d928)
[15:46:17] [DEBUG] CQuery::Execute(this=0x97ddd8, connection=0x97d928)
[15:46:17] [ERROR] error #1054 while executing query "UPDATE `PlayersWeapons` SET `PlayerID` = Jnn_Doug2, `WeaponID` = 24, `Ammo` = 32756": Unknown column 'Jnn_Doug2' in 'field list'
[15:46:17] [DEBUG] CConnection::GetError(this=0x2a30020, connection=0x97d928)
[15:46:17] [DEBUG] CHandle::Execute - return value: true
[15:46:17] [DEBUG] mysql_tquery: return value: '1'
[15:46:17] [DEBUG] cache_is_valid(0)
[15:46:17] [DEBUG] cache_is_valid: return value: 'false'
[15:46:17] [DEBUG] CCallback::Create(amx=0x8a0f00, name='OnQueryError', format='dsssd)
Reply
#2

Uhm, lol i don't really understand something. You want to update the table where the weapons will be saved right ? So.. why you don't use something like this:

PHP код:
new string1000 ];
mysql_formatg_SQLstringsizeof( string ), "UPDATE `PlayersWeapons` SET `WeaponID` = '%d', `Ammo` = '%d' WHERE `PlayerID` = '%s'"Playerplayerid ][ Weapon ], Playerplayerid ][ Ammo ], Playerplayerid ][ Name ] );
mysql_tqueryg_SQLstring"""" ); 
Also, why you use "Player[ playerid ][ Name ]" to get the player id ? I think that variable stores the player name not the id, the id of a player can be simply found if you use "playerid" that's all. I think it will work in the way i made it. If is not working tell me.

EDIT:
Now i get it, you defined the "PlayerName" in the database like "PlayerID" that's really confusing, why you not just use `Name` or something to be more clear for you.
Reply
#3

Quote:
Originally Posted by FaLLenGirL
Посмотреть сообщение
Uhm, lol i don't really understand something. You want to update the table where the weapons will be saved right ? So.. why you don't use something like this:

PHP код:
new string1000 ];
mysql_formatg_SQLstringsizeof( string ), "UPDATE `PlayersWeapons` SET `WeaponID` = '%d', `Ammo` = '%d' WHERE `PlayerID` = '%s'"Playerplayerid ][ Weapon ], Playerplayerid ][ Ammo ], Playerplayerid ][ Name ] );
mysql_tqueryg_SQLstring"""" ); 
Also, why you use "Player[ playerid ][ Name ]" to get the player id ? I think that variable stores the player name not the id, the id of a player can be simply found if you use "playerid" that's all. I think it will work in the way i made it. If is not working tell me.

EDIT:
Now i get it, you defined the "PlayerName" in the database like "PlayerID" that's really confusing, why you not just use `Name` or something to be more clear for you.

I have these logs, but nothing goes for MySQL
Код:
[17:07:50] [INFO] query "UPDATE `PlayersWeapon` SET `WeaponID` = '24', `Ammo` = '32766' WHERE `PlayerID` = 'Jnn_Doug'" successfully executed within 0.310 milliseconds
[17:07:50] [DEBUG] CResultSet::Create(connection=0x6248e0, query_str='UPDATE `PlayersWeapon` SET `WeaponID` = '24', `Ammo` = '32766' WHERE `PlayerID` = 'Jnn_Doug'')
[17:07:50] [DEBUG] created new resultset '0x67efd0'
[17:07:50] [DEBUG] fetched MySQL result '0x0'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)