R39-4 Mysql Plugin wont work! -
PrettyDiamond - 06.02.2016
I cannt find the error! Anyone help me?
PHP код:
forward SaveAccountStats(playerid);
public SaveAccountStats(playerid)
{
if(Logged[playerid] == 1)
{
new query[2048];
mysql_format(g_SQL, query, sizeof(query), "UPDATE `accounts` SET `Cash`=%d, `AdminLevel`=%d, `VIPLevel`=%d, `Kills`=%d, `Deaths`=%d, `Score`=%d, `Rank`=%s, `Headshots`=%d, `Banned`=%d, `Warns`=%d,\
`hours`=%d, `minutes`=%d, `Color`=%d, `Turfs`=%d, `VW`=%d, `Interior`=%d, `PM`=%d, `Clan`=%s, `ClRank`=%d, `ClLeader`=%d, `Invited`=%d, `Inviting`=%d WHERE `ID`=%d",\
Player[playerid][pCash],
Player[playerid][pAdminLevel],
Player[playerid][pVIPLevel],
Player[playerid][pKills],
Player[playerid][pDeaths],
Player[playerid][pScore],
Player[playerid][pRank],
Player[playerid][pHeadshots],
Player[playerid][pBanned],
Player[playerid][pWarns],
Player[playerid][phours],
Player[playerid][pminutes],
Player[playerid][pColor],
Player[playerid][pTurfs],
Player[playerid][pVW],
Player[playerid][pInt],
Player[playerid][pPM],
Player[playerid][pClan],
Player[playerid][pClRank],
Player[playerid][pClLeader],
Player[playerid][pInvited],
Player[playerid][pInviting],
Player[playerid][pID]);
mysql_tquery(g_SQL, query, "", "");
return 1;
}
return 0;
}
And here my mysql log
PHP код:
[15:55:13] [DEBUG] mysql_format - connection: 1, len: 2048, format: "UPDATE `accounts` SET `Cash`=%d, `AdminLevel`=%d, `VIPLevel`=%d, `Kills`=%d, `Deaths`=%d, `Score`=%d, `Rank`=%s, `Headshots`=%d,..."
[15:55:13] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `accounts` SET `Cash`=10000, `AdminLevel`=1339, `VIPLevel", callback: "(null)", format: "(null)"
[15:55:13] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[15:55:13] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' `Headshots`=0, `Banned`=0, `Warns`=0,`hours`=0, `minutes`=11, `Color`=0, `Turfs' at line 1
[15:55:13] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError
Ty for help!
Re: R39-4 Mysql Plugin wont work! -
AmigaBlizzard - 06.02.2016
Try adding
PHP код:
printf("%s", query);
And see what it prints.
Good advice: split up your query into multiple smaller queries, because you never update all these fields all at once while playing the game.
Can't imagine your players having a modified Warns, Banned, Turfs values while just earning a kill for example.
So no need to update data that didn't change.
Re: R39-4 Mysql Plugin wont work! -
PrettyDiamond - 06.02.2016
Hello Amiga, ty for try to help me. Yes before i try this i had that splitted ind smaller queries, and because they dont working, i try to do all in one.
This is the result of print, btw the query dont save data. That what you see with money etc, i insert manual in the DB.
PHP код:
[17:34:52] UPDATE `accounts` SET `Cash`=10000, `AdminLevel`=1339, `VIPLevel`=3, `Kills`=0, `Deaths`=0, `Score`=0, `Rank`=, `Headshots`=0, `Banned`=0, `Warns`=0,`hours`=0, `minutes`=2, `Color`=0, `Turfs`=0, `VW`=0, `Interior`=0, `PM`=0, `Clan`=0, `ClRank`=0, `ClLeader`=0, `Invited`=0, `Inviting`=0 WHERE `ID`=2
Re: R39-4 Mysql Plugin wont work! -
Vince - 06.02.2016
Good advice:
read the error message.
Код:
for the right syntax to use near ' `Headshots`=0,
Quote:
Originally Posted by PrettyDiamond
PHP код:
`Rank`=, `Headshots`=0,
|
Re: R39-4 Mysql Plugin wont work! -
PrettyDiamond - 07.02.2016
I have of course
readed, before posted the log!
and see my `
Rank`=, that isnt INT.
But a varchar.
Because that i have seted it as %s.
PHP код:
mysql_format(g_SQL, query, sizeof(query), "UPDATE `accounts` SET `Cash`=%d, `AdminLevel`=%d, `VIPLevel`=%d, `Kills`=%d, `Deaths`=%d, `Score`=%d, `Rank`=%s, `Headshots`=%d, `Banned`=%d, `Warns`=%d,\
`hours`=%d, `minutes`=%d, `Color`=%d, `Turfs`=%d, `VW`=%d, `Interior`=%d, `PM`=%d, `Clan`=%s, `ClRank`=%d, `ClLeader`=%d, `Invited`=%d, `Inviting`=%d WHERE `ID`=%d",\
I have changed it for '%e' too
PHP код:
new query[2048];
mysql_format(g_SQL, query, sizeof(query), "UPDATE `accounts` SET `Cash`='%d', `AdminLevel`='%d', `VIPLevel`='%d', `Kills`='%d', `Deaths`='%d', `Score`='%d', `Rank`='%s', `Headshots`=%d, `Banned`=%d, `Warns`=%d,\
`hours`='%d', `minutes`='%d', `Color`='%d', `Turfs`='%d', `VW`='%d', `Interior`='%d', `PM`='%d', `Clan`='%s', `ClRank`='%d', `ClLeader`='%d', `Invited`='%d', `Inviting`='%d' WHERE `ID`='%d'",\
but nothing helps here the result, after changes.
PHP код:
[09:50:10] UPDATE `accounts` SET `Cash`='10000', `AdminLevel`='1339', `VIPLevel`='3', `Kills`='0', `Deaths`='1', `Score`='0', `Rank`='', `Headshots`=0, `Banned`=0, `Warns`=0,`hours`='0', `minutes`='23', `Color`='0', `Turfs`='0', `VW`='0', `Interior`='0', `PM`='0', `Clan`='0', `ClRank`='0', `ClLeader`='0', `Invited`='0', `Inviting`='0' WHERE `ID`='2'
Re: R39-4 Mysql Plugin wont work! -
AmigaBlizzard - 10.02.2016
The problem is that you HAVE to use ' around strings.
It's not needed for integers, but because strings may have spaces in them, you need to use ' around the entire string to indicate the beginning and the ending of the string.
Another thing might be that your table may have NOT NULL set as property of the Rank column.
If you're sending an empty string (''), this is NULL and can't be accepted by a column that has NOT NULL enabled.
You might need to check that.
Some advice: for player-inputted strings (like a clan-name or some other stuff), ALWAYS use %e instead of %s to prevent mysql injections.
If some player inputted
PHP код:
'; DROP TABLE accounts; '
as clan-name for example, your entire table is just gone without warning.
For strings generated purely from within the script without any player input, it should be safe enough to use %s but you'll have to be careful anyways.
I'm using %e for ALL strings, even if they aren't player-inputted texts.
Re: R39-4 Mysql Plugin wont work! -
mirou123 - 10.02.2016
Wherever you have %s put it between 's so for example `Rank` = %s should become `Rank` = '%s' or better yet `Rank` = '%e'
Re: R39-4 Mysql Plugin wont work! -
PrettyDiamond - 11.02.2016
So sorry but i cannt fix this i dont konw how more i can do to try to fix it!
@AmigaBlizzard ty for your patience. And all others too! Ty in Advance...
I have a picture of my table: Looks all right about NULL?
table.jpg
and the last logs after i modify the string again:
The string
Код:
new query[2048];
mysql_format(g_SQL, query, sizeof(query), "UPDATE `accounts` SET `Cash`=%d, `AdminLevel`=%d, `VIPLevel`=%d, `Kills`=%d, `Deaths`=%d, `Score`=%d, `Rank`='%s', `Headshots`=%d, `Banned`=%d, `Warns`=%d,\
`hours`=%d, `minutes`=%d, `Color`=%d, `Turfs`=%d, `VW`=%d, `Interior`=%d, `PM`=%d, `Clan`='%s', `ClRank`=%d, `ClLeader`=%d, `Invited`=%d, `Inviting`=%d WHERE `ID`=%d",\
The Logs
Код:
[18:36:50] [DEBUG] mysql_format - connection: 1, len: 2048, format: "UPDATE `accounts` SET `Cash`=%d, `AdminLevel`=%d, `VIPLevel`=%d, `Kills`=%d, `Deaths`=%d, `Score`=%d, `Rank`='%s', `Headshots`=%..."
[18:36:50] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `accounts` SET `Cash`=10000, `AdminLevel`=0, `VIPLevel`=0", callback: "(null)", format: "(null)"
[18:36:50] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[18:36:50] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 0.647 milliseconds
[18:36:50] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
Код:
[18:36:40] UPDATE `accounts` SET `Cash`=10000, `AdminLevel`=0, `VIPLevel`=0, `Kills`=0, `Deaths`=5, `Score`=0, `Rank`='', `Headshots`=0, `Banned`=0, `Warns`=0,`hours`=1, `minutes`=12, `Color`=0, `Turfs`=0, `VW`=0, `Interior`=0, `PM`=0, `Clan`='0', `ClRank`=0, `ClLeader`=0, `Invited`=0, `Inviting`=0 WHERE `ID`=4
btw i have also tried with `Rank`='%e' same results.
Re: R39-4 Mysql Plugin wont work! -
AmigaBlizzard - 11.02.2016
Your logs show that the query has been executed successfully, so it should work already.
Your NULL column shows "Nein" everywhere.
This means that all your fields MUST have data in them.
You could create a test table and play with them for a while to test all settings, that's what I do most of the time when testing something new.
Your test table only needs a few columns with integer, float and varchar datatypes.
If you have Navicat, you can insert some test-data as well into your tables and it displays the proper query at the bottom of the program so you can look at the query-structure.