SA-MP Forums Archive
Error with MYSQL and Toys - 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: Error with MYSQL and Toys (/showthread.php?tid=640607)



Error with MYSQL and Toys - Dello - 04.09.2017

Hello there! I am using a system to save a Toys and i have this problem..


Log
Код:
MYSQL - 	ERRORID: 1064
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `Nombre` = Steven_Dominguez' at line 1
Query: WHERE `Nombre` = Steven_Dominguez
Callback: OnQueryFinish
Script code:

Код:
stock ActualizarAccesorios(playerid, slot=-1)
{
	if(slot == -1)
	{
		Loop(i, MAX_ACCESORIOS, 0)
		{
			ActualizarAccesorios(playerid, i);
		}
	}
	else if(slot > -1 && slot < MAX_ACCESORIOS)
	{
		new
			querystr [300] = "UPDATE `usuarios` SET ",
			str [500];

		A_Format (str, "`AttachModel_%d` = %d,", slot, InfoJugador[playerid][jAttachModel][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachBone_%d` = %d,", slot, InfoJugador[playerid][jAttachModel][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachPosx_%d` = %f,", slot, InfoJugador[playerid][jAttachPosx][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachPosy_%d` = %f,", slot, InfoJugador[playerid][jAttachPosy][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachPosz_%d` = %f,", slot, InfoJugador[playerid][jAttachPosz][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachAngx_%d` = %f,", slot, InfoJugador[playerid][jAttachAngx][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachAngy_%d` = %f,", slot, InfoJugador[playerid][jAttachAngy][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachAngz_%d` = %f,", slot, InfoJugador[playerid][jAttachAngz][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachEscx_%d` = %f,", slot, InfoJugador[playerid][jAttachEscx][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachEscy_%d` = %f,", slot, InfoJugador[playerid][jAttachEscy][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachEscz_%d` = %f,", slot, InfoJugador[playerid][jAttachEscz][slot]);
		strcat (querystr, str);

		A_Format (str, "`AttachOcultado_%d` = %d ", slot, InfoJugador[playerid][jAttachOcultado][slot]);

		A_Format (str, "WHERE `Nombre` = %s", pName (playerid));
		strcat (querystr, str);
		opmysql_tquery(str, "OnQueryFinish", "ii", playerid, query_type_unknown);
	}
	return 1;
}
I need a answer, i didn't find the correct form


Re: Error with MYSQL and Toys - Meller - 04.09.2017

First off, ALWAYS escape your strings in MySQL using %e. Second, a string must be formatted in two quotes.

Quote:
Originally Posted by Vince
Посмотреть сообщение
Oh for the love of ... Just use %e in mysql_format for whatever text you insert wherever. If it doesn't help it doesn't hurt either.




Respuesta: Error with MYSQL and Toys - Dello - 05.09.2017

For example? Where i put "%e" ?


Re: Error with MYSQL and Toys - Luke_James - 05.09.2017

You need to escape strings (anything which isn't an integer (which is a number, such as 1, or 394832 for which you use %d) or a floating point variable (such as 180.0000 for which you use %f)). So, in your code, only the Name (Nombre) is a string, because a name is a string of text like Dello, or Luke_James.


Respuesta: Error with MYSQL and Toys - Dello - 05.09.2017

So... i need to change in my code the strings in "%d" for "%s" ?
Sorry for my bad inteligence....


їCan you give me a example with code? Thx bro!


Re: Error with MYSQL and Toys - Luke_James - 05.09.2017

Change %s to %e, because %s represents a string (the name) which you need to escape. %e escapes data directly. Do not change %d or %f; they are integer specifiers, not strings. Here's a simple guide...

%s = string (a string of text, for example Dello, San Andreas Multiplayer, pizza123)
%d = integer (a whole number, for example 1, 53, 1000, 192384)
%f = floating point value (a decimal number, in simplest terms*, for example 90.0000, 5.3923)

* a number's binary point which can be placed relative to the significant figures of the number.


Re: Error with MYSQL and Toys - Jefff - 05.09.2017

pawn Код:
A_Format (str, "WHERE `Nombre` = '%s'", pName (playerid));



Respuesta: Error with MYSQL and Toys - Dello - 05.09.2017

Oh Thank you for the mini-tutorial! haha
Now i have this error:
Код:
MYSQL - 	ERRORID: 1064
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `Nombre` = e' at line 1
Query: WHERE `Nombre` = e
Callback: OnQueryFinish
And, i change the last of the code:
Код:
A_Format (str, "WHERE `Nombre` = %e", pName (playerid));
		strcat (querystr, str);
		opmysql_tquery(str, "OnQueryFinish", "ii", playerid, query_type_unknown);



Respuesta: Re: Error with MYSQL and Toys - Dello - 05.09.2017

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
A_Format (str, "WHERE `Nombre` = '%s'", pName (playerid));
I change too this, and new error:
Код:
[04/09/2017 22:02:56] 
MYSQL - 	ERRORID: 1064
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `Nombre` = 'Steven_Dominguez'' at line 1
Query: WHERE `Nombre` = 'Steven_Dominguez'
Callback: OnQueryFinish



Re: Error with MYSQL and Toys - Luke_James - 05.09.2017

Remember to include quotes (apostrophes ' ') in strings

PHP код:
A_Format (str"WHERE `Nombre` = '%e'"pName (playerid));