SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 07/01/2016, 12:48 AM   #1
danielpalade
Huge Clucker
 
Join Date: Aug 2013
Posts: 387
Reputation: 1
Default SavePlayer Mysql

This is my saveplayer.
Code:
stock SavePlayer(playerid)
{
	new query[1024], aName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, aName, sizeof(aName));
	mysql_format(mysql, query, sizeof(query), "UPDATE accounts SET AdminLevel = '%d', Skin = '%d', Money = '%d', Level = '%d', Job = '%d', Materials = '%d', Drugs ='%d', Lic1 = '%d', Warns ='%d', Mute = '%d', Group = '%d', GroupRank = '%d', Spawn = '%d' WHERE ID = '%d'", 
	pInfo[playerid][pAdminLevel], GetPlayerSkin(playerid), GetPlayerMoney(playerid), GetPlayerScore(playerid), pInfo[playerid][pJob], pInfo[playerid][pMaterials], pInfo[playerid][pDrugs], pInfo[playerid][pLic1], pInfo[playerid][pWarns], pInfo[playerid][pMute], pInfo[playerid][pGroup], pInfo[playerid][pGroupRank], pInfo[playerid][pSpawn], pInfo[playerid][pID]);
	mysql_tquery(mysql, query);
	
	printf("Player ID %d (%s) has been saved", playerid, GetName(playerid));
}
Whenever someone disconnects from the server their data should save, but I get this error in the mysq log.

Code:
[01:44:33] [DEBUG] mysql_format - connection: 1, len: 1024, format: "UPDATE accounts SET AdminLevel = '%d', Skin = '%d', Money = '%d', Level = '%d', Job = '%d', Materials = '%d', Drugs ='%d', Lic1 ..."
[01:44:33] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE accounts SET AdminLevel = '3', Skin = '217', Money = '749", callback: "(null)", format: "(null)"
[01:44:33] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[01:44:33] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Group = '0', GroupRank = '0', Spawn = '0' WHERE ID = '35'' at line 1
[01:44:33] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError
I have no idea what I did wrong..
danielpalade is offline   Reply With Quote
Old 07/01/2016, 01:16 AM   #2
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,086
Reputation: 2655
Default Re: SavePlayer Mysql

GROUP is an SQL keyword and as such shouldn't be used as a column name.
__________________
Vince is offline   Reply With Quote
Old 07/01/2016, 09:29 AM   #3
danielpalade
Huge Clucker
 
Join Date: Aug 2013
Posts: 387
Reputation: 1
Default Re: SavePlayer Mysql

Quote:
Originally Posted by Vince View Post
GROUP is an SQL keyword and as such shouldn't be used as a column name.
Could you explain better? What do I need to change?
danielpalade is offline   Reply With Quote
Old 07/01/2016, 10:07 AM   #4
Mencent
High-roller
 
Mencent's Avatar
 
Join Date: Mar 2015
Location: Lower Saxony (Niedersachsen)
Posts: 1,314
Reputation: 92
Default Re: SavePlayer Mysql

Hello!

When you write "Group" like this:
PHP Code:
`Group` = '%d' 
then it will be work.
PHP Code:
stock SavePlayer(playerid)
{
    new 
query[1024], aName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridaNamesizeof(aName));
    
mysql_format(mysqlquerysizeof(query), "UPDATE accounts SET AdminLevel = '%d', Skin = '%d', Money = '%d', Level = '%d', Job = '%d', Materials = '%d', Drugs ='%d', Lic1 = '%d', Warns ='%d', Mute = '%d', `Group` = '%d', GroupRank = '%d', Spawn = '%d' WHERE ID = '%d'",
    
pInfo[playerid][pAdminLevel], GetPlayerSkin(playerid), GetPlayerMoney(playerid), GetPlayerScore(playerid), pInfo[playerid][pJob], pInfo[playerid][pMaterials], pInfo[playerid][pDrugs], pInfo[playerid][pLic1], pInfo[playerid][pWarns], pInfo[playerid][pMute], pInfo[playerid][pGroup], pInfo[playerid][pGroupRank], pInfo[playerid][pSpawn], pInfo[playerid][pID]);
    
mysql_tquery(mysqlquery);

    
printf("Player ID %d (%s) has been saved"playeridGetName(playerid));

__________________
Best wishes,
Mencent

(Sorry for my bad english, I hope you can understand this!)
Mencent is offline   Reply With Quote
Old 07/01/2016, 10:10 AM   #5
BroZeus
High-roller
 
BroZeus's Avatar
 
Join Date: Jan 2014
Location: India
Posts: 1,405
Reputation: 173
Default Re: SavePlayer Mysql

He means that Group is a MySQL reserved keyword like in PAWN if and else are keywords so they shouldn't be used as a variable name, similarly Group shouldn't be used as column name.
It shouldn't be used but you can use it you just need to enclose Group around ``. So query becomes
Quote:
... `Group` = ...
__________________


"Be the change that you wish to see in the world."

Check out my Github profile!
BroZeus is offline   Reply With Quote
Old 07/01/2016, 10:20 AM   #6
HarrisonC
Big Clucker
 
HarrisonC's Avatar
 
Join Date: Aug 2012
Location: United Kingdom
Posts: 72
Reputation: 21
Default Re: SavePlayer Mysql

Might not be valid to your case but for future reference, avoid using 'Desc' as this is another column name along with 'Group' that cannot be used due to it being a SQL keyword.
__________________
HarrisonC is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL SavePlayer problem McGuiness Scripting Help 2 03/10/2014 08:02 PM
[Tutorial] [VIDEO] MySQL ORM r38: How to pair GM with MySQL & creation of registration/connection system cArnasLT Tutorials 3 19/05/2014 03:08 PM
BlueG MySQL plugin - Failed (plugins/mysql.so: undefined symbol: _Z13stringvprintfPKcPc) linuxthefish Plugin Development 10 13/07/2013 11:56 AM
Mysql SavePlayer(playerid) error! Georgelopez1 Help Archive 8 01/05/2011 06:27 PM


All times are GMT. The time now is 09:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.