Mysql Query Error
#1

pawn Код:
function SavePlayerStats(playerid)
{
    format(str, sizeof(str), "UPDATE `Users` SET `Money` = '%d', `Gender` = '%d', `ppos_x` = '%d', `ppos_y` = '%d', `ppos_z` = '%d', `Level` = '%d' ` WHERE `user` = '%s'",UserStats[playerid][Money], UserStats[playerid][Gender],UserStats[playerid][ppos_x],UserStats[playerid][ppos_y],UserStats[playerid][ppos_z],UserStats[playerid][Level],pName(playerid));
    mysql_query(str);
    return 1;
}
I get a mysql query error for this:
pawn Код:
[Mon Jan 10 22:47:19 2011] Function: mysql_query executed: "UPDATE `Users` SET `Money` = '0', `Gender` = '1', `ppos_x` = '0', `ppos_y` = '0', `ppos_z` = '0', `Level` = '0' ` WHERE `user` = 'Tyrone_Williamss'" with result: "1".
[Mon Jan 10 22:47:19 2011] Error (0): Failed to exeute query. 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 '` WHERE `user` = 'Tyrone_Williamss'' at line 1.
Anyone notice a problem?
Reply
#2

You accidentally (I presume) added an extra `
pawn Код:
function SavePlayerStats(playerid)
{
    format(str, sizeof(str), "UPDATE `Users` SET `Money` = '%d', `Gender` = '%d', `ppos_x` = '%df, `ppos_y` = '%f', `ppos_z` = '%f', `Level` = '%d' WHERE `user` = '%s';",UserStats[playerid][Money], UserStats[playerid][Gender],UserStats[playerid][ppos_x],UserStats[playerid][ppos_y],UserStats[playerid][ppos_z],UserStats[playerid][Level],pName(playerid));
    mysql_query(str);
    return 1;
}
Edit: Positions should be floats (%f).
Reply
#3

You are adding apostrophe's around your numerical variables (%d). You should be adding these; ` (same as the ~ key). You should also keep in mind you need to add apostrophe's around your string variables (%s); not `'s.
Reply
#4

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
You are adding apostrophe's around your numerical variables (%d). You should be adding these; ` (same as the ~ key). You should also keep in mind you need to add apostrophe's around your string variables (%s); not `'s.
Whatever you just stated doesn't count in this particular query. He did add apostrophe's around the string and if you decide to do it on integers has nothing to say.
Reply
#5

pawn Код:
Error (0): Failed to exeute query. Unknown column 'user' in 'where clause'.
Is my new error after your fix
Reply
#6

You prob forgot to capitalize user when making this query, I don't know your database structure.
pawn Код:
function SavePlayerStats(playerid)
{
    format(str, sizeof(str), "UPDATE `Users` SET `Money` = '%d', `Gender` = '%d', `ppos_x` = '%df, `ppos_y` = '%f', `ppos_z` = '%f', `Level` = '%d' WHERE `User` = '%s';",UserStats[playerid][Money], UserStats[playerid][Gender],UserStats[playerid][ppos_x],UserStats[playerid][ppos_y],UserStats[playerid][ppos_z],UserStats[playerid][Level],pName(playerid));
    mysql_query(str);
    return 1;
}
Reply
#7

alright, now i run into this:

pawn Код:
Error (0): Failed to exeute query. 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 '0.000000', `ppos_z` = '0.000000', `Level` = '0' WHERE `User` = 'Tyrone_Williamss' at line 1.
Reply
#8

Lol,

pawn Код:
format(str, sizeof(str), "UPDATE `Users` SET `Money` = '%d', `Gender` = '%d', `ppos_x` = '%f, `ppos_y` = '%f', `ppos_z` = '%f', `Level` = '%d' WHERE `User` = '%s';",UserStats[playerid][Money], UserStats[playerid][Gender],UserStats[playerid][ppos_x],UserStats[playerid][ppos_y],UserStats[playerid][ppos_z],UserStats[playerid][Level],pName(playerid)
Reply
#9

nvm, fixed it, you put an extra "d" in your last fix for me, thanks for help.
Reply
#10

That's my bad, accidently added a d instead of a ' somewhere. ^lol

pawn Код:
function SavePlayerStats(playerid)
{
    format(str, sizeof(str), "UPDATE `Users` SET `Money` = '%d', `Gender` = '%d', `ppos_x` = '%f', `ppos_y` = '%f', `ppos_z` = '%f', `Level` = '%d' WHERE `User` = '%s';",UserStats[playerid][Money], UserStats[playerid][Gender],UserStats[playerid][ppos_x],UserStats[playerid][ppos_y],UserStats[playerid][ppos_z],UserStats[playerid][Level],pName(playerid));
    mysql_query(str);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)