MySQL doesn't update table?
#1

So I'm trying to learn MySQL, for some reason loading information into player seems to work fine, but updating the data when a player leaves doesn't.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new query[512];
    new Float: tmpX, Float: tmpY, Float: tmpZ, Float: tmpA;

    GetPlayerPos(playerid, tmpX, tmpY, tmpZ);
    GetPlayerFacingAngle(playerid, tmpA);

    pData[playerid][p_SavePosInterior] = GetPlayerInterior(playerid);
    pData[playerid][p_SavePosVW] = GetPlayerVirtualWorld(playerid);

    mysql_format(mysql, query, sizeof query, "UPDATE `players` SET `AdminLevel`=%d `SavePos`=%d `SavePosX`=%f `SavePosY`=%f `SavePosZ`=%f `SavePosA`=%f `SavePosInterior`=%d `SavePosVW`=%d `Kills`=%d `Deaths`=%d \
                    `Score`=%d `Money`=%d WHERE ID=%d"
, pData[playerid][p_AdminLevel], pData[playerid][p_SavePos], tmpX, tmpY, tmpZ, tmpA,
                    pData[playerid][p_SavePosInterior], pData[playerid][p_SavePosVW], pData[playerid][p_Kills], pData[playerid][p_Deaths], GetPlayerScore(playerid), GetPlayerMoney(playerid), pData[playerid][p_ID]);

    mysql_tquery(mysql, query, "", "");
    return 1;
}
And generally, does anyone know any good place to start learning?
I've read so many tutorials on the forum, but it seems like none of them explains the BASIC of the language, making it really hard to understand.
Reply
#2

Escape float like this :
Код:
`SavePosX`='%f' `SavePosY`='%f' `SavePosZ`='%f' `SavePosA`='%f'
You can learn mysql from this site http://www.w3schools.com/sql/
Reply
#3

Quote:
Originally Posted by bondowocopz
Посмотреть сообщение
Escape float like this :
Код:
`SavePosX`='%f' `SavePosY`='%f' `SavePosZ`='%f' `SavePosA`='%f'
You can learn mysql from this site http://www.w3schools.com/sql/
Thanks for the site, it looks great for starting out.

But the data still won't update.
pawn Код:
mysql_format(mysql, query, sizeof query, "UPDATE `players` SET `AdminLevel`=%d `SavePos`=%d `SavePosX`='%f' `SavePosY`='%f' `SavePosZ`='%f' `SavePosA`='%f' `SavePosInterior`=%d `SavePosVW`=%d `Kills`=%d `Deaths`=%d \
                    `Score`=%d `Money`=%d WHERE ID=%d"
, pData[playerid][p_AdminLevel], pData[playerid][p_SavePos], tmpX, tmpY, tmpZ, tmpA,
                    pData[playerid][p_SavePosInterior], pData[playerid][p_SavePosVW], pData[playerid][p_Kills], pData[playerid][p_Deaths], GetPlayerScore(playerid), GetPlayerMoney(playerid), pData[playerid][p_ID]);
Reply
#4

In the root of your server, you will find a log file for MySQL. Does that contain any errors?
Reply
#5

Quote:
Originally Posted by mamorunl
Посмотреть сообщение
In the root of your server, you will find a log file for MySQL. Does that contain any errors?
Yeah you're right!
It says my SQL syntax contains an error, but it seems fine to me...
Quote:

[17:20:37] [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 '`SavePos`=0 `SavePosX`='1959.273' `SavePosY`='1343.243' `SavePosZ`='15.375' `Sav' at line 1

Reply
#6

You have to separate the fields it's going to update by a comma:
pawn Код:
"... SET `AdminLevel`=%d, `SavePos`=%d, `SavePosX`=%f, `SavePosY`=%f, `SavePosZ`=%f, ..."
and no need to use ` ` around fields' or table's name and neither ' ' around integers or float; although it's a must in strings.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You have to separate the fields it's going to update by a comma:
pawn Код:
"... SET `AdminLevel`=%d, `SavePos`=%d, `SavePosX`=%f, `SavePosY`=%f, `SavePosZ`=%f, ..."
and no need to use ` ` around fields' or table's name and neither ' ' around integers or float; although it's a must in strings.
Still, I'm getting the same error:
pawn Код:
mysql_format(mysql, query, sizeof query, "UPDATE `players` SET `AdminLevel`=%d, `SavePos`=%d,, `SavePosX`=%f, `SavePosY`=%f, `SavePosZ`=%f, `SavePosA`=%f, `SavePosInterior`=%d, `SavePosVW`=%d, `Kills`=%d, `Deaths`=%d, \
                    `Score`=%d, `Money`=%d WHERE `ID`=%d"
, pData[playerid][p_AdminLevel], pData[playerid][p_SavePos], tmpX, tmpY, tmpZ, tmpA,
                    pData[playerid][p_SavePosInterior], pData[playerid][p_SavePosVW], pData[playerid][p_Kills], pData[playerid][p_Deaths], GetPlayerScore(playerid), GetPlayerMoney(playerid), pData[playerid][p_ID]);
The error:
Quote:

[17:48: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 ' `SavePosX`=1955.152, `SavePosY`=1367.763, `SavePosZ`=9.258, `SavePosA`=3.203, `' at line 1
It's strange that the error is only pointing at the floats part... Are you sure there is no need to use ' ' around them?
Reply
#8

Print the query and check if the string length is enough.
Reply
#9

Oh god.
I've had an extra comma after `SavePos=%d`,,
Wouldn't have seen it without printing it, so thanks for that!

Thanks everyone.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)