format(string,sizeof(string),"INSERT INTO `logs_admin` (`Nombre`,`Administrador`,`Tipo`,`Motivo`,`Tiempo`,`IP`,`IP_Administrador`) VALUES ('%s','%s','1','%s','%d','%s','%s')",GetPlayerNameRP(playerid2),GetPlayerNameRP(playerid),(result),time,plr2IP,plrIP); mysql_query(1, string);
[16:43:02] [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 ''Loga' at line 1 [16:43:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
mysql_query(1, string);
Код:
mysql_query(1, string); |
if(strcmp(cmd, "/jail", true) == 0) { if(PlayerInfo[playerid][pAdmin] < 1){SendClientMessage(playerid, Rojo, "* Nivel de admin insuficiente."); return 1;} tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, Naranja, "* /Jail [ID] [Tiempo] [Razуn]"); return 1; } playerid2 = ReturnUser(tmp); tmp = strtok(cmdtext, idx); new time = strval(tmp); if(!IsNumeric(tmp) && !strlen(tmp)) { SendClientMessage(playerid, Naranja, "* /Jail [ID] [Tiempo] [Razуn]"); return 1; } if(time < 0){SendClientMessage(playerid, Rojo, "* No puedes poner un tiempo negativo."); return 1;} if(IsPlayerConnected(playerid2) && playerid2 != INVALID_PLAYER_ID) { new length = strlen(cmdtext); while ((idx < length) && (cmdtext[idx] <= ' ')) { idx++; } new offset = idx; new result[128]; while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))) { result[idx - offset] = cmdtext[idx]; idx++; } result[idx - offset] = EOS; if(!strlen(result)) { SendClientMessage(playerid, Naranja, "* /Jail [ID] [Tiempo] [Razуn]"); return 1; } new ano, mes, dia; getdate(ano, mes, dia); new plrIP[16]; GetPlayerIp(playerid, plrIP, sizeof(plrIP)); new plr2IP[16]; GetPlayerIp(playerid2, plr2IP, sizeof(plr2IP)); format(Nombre2, sizeof(Nombre2),"%s", GetPlayerNameRP(playerid2)); format(Nombre, sizeof(Nombre),"%s", GetPlayerNameRP(playerid)); format(string, sizeof(string), "'%s' ha sido jaileado por %d minutos. Motivo: %s. (%d/%d/%d)", Nombre2, time, (result), dia, mes, ano); SendClientMessageToAll(Rojo, string); format(string, sizeof(string), "Has sido jaileado por '%s' durante %d minutos.", Nombre, time); SendClientMessage(playerid2, Celeste, string); format(string, sizeof(string), "Si crees que fue un error puedes utilizar /w para comunicarte con el administrador."); SendClientMessage(playerid2, Celeste, string); printf("S > [Staff] %s ha jaileado a %s %d minutos por: %s", Nombre, Nombre2, time, (result)); format(string,sizeof(string),"INSERT INTO `logs_admin` (`Nombre`,`Administrador`,`Tipo`,`Motivo`,`Tiempo`,`IP`,`IP_Administrador`) VALUES ('%s','%s','1','%s','%d','%s','%s')",GetPlayerNameRP(playerid2),GetPlayerNameRP(playerid),(result),time,plr2IP,plrIP); mysql_query(1, string); PlayerInfo[playerid2][pEncarcelado] = 3; PlayerInfo[playerid2][pTiempoCarcel] = time; if(time <= 0){UnJailPlayerOOC(playerid2); return 1;} SetTimerEx("JailPlayerOOC",100,0,"d",playerid2); } else { SendClientMessage(playerid,Rojo,"* ID invбlida."); } return 1; }
Escape strings. Instead of '%s' specifier for strings, use '%q' in format or '%e' in mysql_format
|
format(string,sizeof(string),"INSERT INTO `logs_admin` (`Nombre`,`Administrador`,`Tipo`,`Motivo`,`Tiempo`,`IP`,`IP_Administrador`) VALUES ('%q','%q','1','%q','%q','%q','%q')",GetPlayerNameRP(playerid2),GetPlayerNameRP(playerid),(result),time,plr2IP,plrIP); mysql_query(1, string);
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 ''' at line 1
Seems like %q specifier replaces with '' instead of \', at least that's what it printed for a single apostrophe.
Just use mysql_format and '%e' and you'll have no problems. --- As for strtok and non-threaded queries, consider use better methods (sscanf and threaded queries). |
format(string,sizeof(string),"INSERT INTO `logs_admin` (`Nombre`,`Administrador`,`Tipo`,`Motivo`,`Tiempo`,`IP`,`IP_Administrador`) VALUES ('%e','%e','1','%e','%e','%e','%e')",GetPlayerNameRP(playerid2),GetPlayerNameRP(playerid),(result),time,plr2IP,plrIP); mysql_query(1, string);
[17:38:14] [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 ''e' at line 1 [17:38:14] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[..]
Just use mysql_format and '%e' and you'll have no problems. [..] |
mysql_format(1, string,sizeof(string),"...", ...);
format( string, sizeof( string ), "INSERT INTO `logs_admin` (`Nombre`,`Administrador`,`Tipo`,`Motivo`,`Tiempo`,`IP`,`IP_Administrador`) VALUES ('%s','%s',1,'%s','%d','%s','%s')", GetPlayerNameRP( playerid2 ), GetPlayerNameRP( playerid ), result, time, plr2IP, plrIP ); mysql_query(1, string);
I have only taken a quick look at this however, you put apostrophes around an integer:
I have made it bold Код:
format( string, sizeof( string ), "INSERT INTO `logs_admin` (`Nombre`,`Administrador`,`Tipo`,`Motivo`,`Tiempo`,`IP`,`IP_Administrador`) VALUES ('%s','%s',1,'%s','%d','%s','%s')", GetPlayerNameRP( playerid2 ), GetPlayerNameRP( playerid ), result, time, plr2IP, plrIP ); mysql_query(1, string); |