MySQL error
#1

Hi there! im getting an error and i really need help

Код:
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);
Error
Код:
[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
Reply
#2

Код:
mysql_query(1, string);
using old mysql I am sure it didn't work like this too. Show me full code.
Reply
#3

Quote:
Originally Posted by Humza
Посмотреть сообщение
Код:
mysql_query(1, string);
using old mysql I am sure it didn't work like this too. Show me full code.
Код:
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;
}
Reply
#4

Escape strings. Instead of '%s' specifier for strings, use '%q' in format or '%e' in mysql_format
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
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
Reply
#6

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).
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
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
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
[..]

Just use mysql_format and '%e' and you'll have no problems.

[..]
Код:
mysql_format(1, string,sizeof(string),"...", ...);
Reply
#9

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);
You only need to put apostrophes around values that are of a string type. If its a integer / decimal / float it does not need to be wrapped in apostrophes.
Reply
#10

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Код:
mysql_format(1, string,sizeof(string),"...", ...);
Thank you! Working now! <3

Quote:
Originally Posted by azzerking
Посмотреть сообщение
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);
You only need to put apostrophes around values that are of a string type. If its a integer / decimal / float it does not need to be wrapped in apostrophes.
Thank you very much!!!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)