SA-MP Forums Archive
+rep Mysql syntax error - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: +rep Mysql syntax error (/showthread.php?tid=318090)



+rep Mysql syntax error - PawnoQ - 13.02.2012

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();



Re: +rep Mysql syntax error - [MG]Dimi - 13.02.2012

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.


Re: +rep Mysql syntax error - fordawinzz - 13.02.2012

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..


Re: +rep Mysql syntax error - PawnoQ - 13.02.2012

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);



Re: +rep Mysql syntax error - [MG]Dimi - 14.02.2012

Can you show me error from mysql log?


Re: +rep Mysql syntax error - FarSe. - 14.02.2012

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);