+rep Mysql syntax error
#1

hi,

im getting a syntax error on this part of the code, what might cause this error?(at the INSERT INTO part)

pawn Код:
new ClothingReAttachementDataID[MAX_PLAYERS][3],
    Float:ClothingReAttachementDataFloat[MAX_PLAYERS][6];


new pname[24],query[128],queryc[256];
GetPlayerName(playerid,pname,24);
format(query, sizeof(query), "SELECT name FROM `clothes` WHERE name = '%s' LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
    format(queryc, sizeof(queryc), "INSERT INTO `clothes` (name, index, model, bone, fOffsetX, fOffsetY, fOffsetZ, fRotX, fRotY, fRotZ) VALUES('%s','%d','%d','%d','%f','%f','%f','%f','%f','%f')",
    pname,ClothingReAttachementDataID[playerid][0],ClothingReAttachementDataID[playerid][1],ClothingReAttachementDataID[playerid][2],ClothingReAttachementDataFloat[playerid][0],ClothingReAttachementDataFloat[playerid][1],ClothingReAttachementDataFloat[playerid][2],ClothingReAttachementDataFloat[playerid][3],ClothingReAttachementDataFloat[playerid][4],ClothingReAttachementDataFloat[playerid][5]);
    mysql_query(queryc);
}
mysql_free_result();
Reply
#2

pawn Код:
new pname[24],query[128],queryc[256];
GetPlayerName(playerid,pname,24);
format(query, sizeof(query), "SELECT `name` FROM `clothes` WHERE `name` = '%s' LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
    format(queryc, sizeof(queryc), "INSERT INTO `clothes` (`name`,`index`, `model`, `bone`, `fOffsetX`, `fOffsetY`, `fOffsetZ`, `fRotX`, `fRotY`, `fRotZ`) VALUES('%s','%d','%d','%d','%f','%f','%f','%f','%f','%f')",
    pname,ClothingReAttachementDataID[playerid][0],ClothingReAttachementDataID[playerid][1],ClothingReAttachementDataID[playerid][2],ClothingReAttachementDataFloat[playerid][0],ClothingReAttachementDataFloat[playerid][1],ClothingReAttachementDataFloat[playerid][2],ClothingReAttachementDataFloat[playerid][3],ClothingReAttachementDataFloat[playerid][4],ClothingReAttachementDataFloat[playerid][5]);
    mysql_query(queryc);
}
mysql_free_result();
Should work. ALWAYS put table names and Column names between grave ( ` ). Like that MySQL can't make mistake between SQL Syntax and Column/Table name.
Reply
#3

pawn Код:
format(query, sizeof(query), "SELECT `name` FROM `clothes` WHERE LOWER(name) = LOWER('%s') LIMIT 1", pname);
pawn Код:
format(queryc, sizeof(queryc), "INSERT INTO `clothes` (name, index, model, bone, fOffsetX, fOffsetY, fOffsetZ, fRotX, fRotY, fRotZ) VALUES ('%s','%d','%d','%d','%f','%f','%f','%f','%f','%f');",
also, you could put anything else instead of name..
Reply
#4

thx, that works
but this doesnt work yet:

pawn Код:
format(queryc, sizeof(queryc), "UPDATE `clothes` SET `index`='%d', `model`='%d', `bone`='%d', `fOffsetX`='%f', `fOffsetY`='%f', `fOffsetZ`='%f', `fRotX`='%f', `fRotY`='%f', `fRotZ`='%f' WHERE `name`='%s'",
pname,ClothingReAttachementDataID[playerid][0],ClothingReAttachementDataID[playerid][1],ClothingReAttachementDataID[playerid][2],ClothingReAttachementDataFloat[playerid][0],ClothingReAttachementDataFloat[playerid][1],ClothingReAttachementDataFloat[playerid][2],ClothingReAttachementDataFloat[playerid][3],ClothingReAttachementDataFloat[playerid][4],ClothingReAttachementDataFloat[playerid][5]);
mysql_query(queryc);
Reply
#5

Can you show me error from mysql log?
Reply
#6

pname should be the last parameter,no the first one.

format(queryc, sizeof(queryc), "UPDATE `clothes` SET `index`='%d', `model`='%d', `bone`='%d', `fOffsetX`='%f', `fOffsetY`='%f', `fOffsetZ`='%f', `fRotX`='%f', `fRotY`='%f', `fRotZ`='%f' WHERE `name`='%s'",
ClothingReAttachementDataID[playerid][0],ClothingReAttachementDataID[playerid][1],ClothingReAttachementDataID[playerid][2],ClothingReAttachementDataFloat[playerid][0],ClothingReAttachementDataFloat[playerid][1],ClothingReAttachementDataFloat[playerid][2],ClothingReAttachementDataFloat[playerid][3],ClothingReAttachementDataFloat[playerid][4],ClothingReAttachementDataFloat[playerid][5],pname);
mysql_query(queryc);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)