mysql saving
#1

Hello guys, i am having some trouble saving my interior ID into my mysql database, I will post the query format of the mysql where it saves. I can't seem to get what the problem is here, tried everything
pawn Код:
mysql_format(Pipeline, szQuery, sizeof(szQuery), "UPDATE `accounts` SET `Level`=%d, `Gender`=%d, `Admin`=%d,  `Skin`=%d, `helper`=%d, `donator`=%d, `leader`=%d, `faction`=%d, `rank`=%d, `interior`=%d, `posX`=%f, `posY`=%f, `posZ`=%f, `posA`=%f WHERE `Username`='%s'",
    PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pGender], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pHelper], PlayerInfo[playerid][pDonator], PlayerInfo[playerid][pLeader], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pInterior], PlayerInfo[playerid][PosX], PlayerInfo[playerid][PosY], PlayerInfo[playerid][PosZ], PlayerInfo[playerid][FA], GetName(playerid));
I will also post 2 lines that came from the mysql log that i fixed somehow but maybe its also related to this problem.

Код:
[22:48:53] [ERROR] CMySQLQuery::Execute[OnQueryFinish] - (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 '`posX`=247.04, `posY`=114.546, `posZ`=1003.219, `posA` =326.956 WHERE `Username`' at line 1
[22:49:40] [ERROR] CMySQLQuery::Execute[OnQueryFinish] - (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 '`posX`=132.0, `posY`=-67.291, `posZ`=1.578, `posA` =0.0 WHERE `Username`='Heinri' at line 1
Thanks for helping in advance
Reply
#2

BUMP
Reply
#3

BUMP
Reply
#4

What size did you make your "szQuery", using "new szQuery[];"

Seems like it could be just too small looking at your first error-message because the name is cut-off, where the last characters don't get inserted properly.

Can I also make a suggestion?
Make many smaller queries, updating only the info that gets changed.
Gender doesn't change alot, so does skin and several other values.

Only change the skin using a small query when the skin is changed.
When the gender changes, use a small query that only updates the gender.
When money changed, only update the money.
It has no use to update 100 fields when only 1 value has changed.
You're just putting more stress on your server, because you're telling mysql to overwrite all given fields by the given values, while most of them just stay the same.

If you write a topic on this forum and you must fix a typo for example, do you completely rewrite the entire post (update ALL fields in the database, where 99% of it stays the same), or just fix the typo (update only the field you need to change)? A stupid comparison probably, but accurate.

This makes it easier to maintain such queries.
With such a long query, it's easy to make a mistake.

Also, for your name, when using mysql_format, use %e instead of %s for strings entered by a player (the name is such a string).
Players might enter a name like "J; DROP TABLE accounts;"
Not many people do this though, but you only need one such player to delete your entire database (MySQL injection).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)