MySQL Syntax
#1

Hello, i made code:
Код:
if(pInfo[playerid][m1id] != 0)
	{
	    new Float:vehx, Float:vehy, Float:vehz, Float:veha, vid1;
		GetVehiclePos(pInfo[playerid][m1id], vehx, vehy, vehz);
		GetVehicleZAngle(pInfo[playerid][m1id], veha);
		vid1 = pInfo[playerid][m1id];
		MySQLCheck();
		format(query, sizeof(query), "UPDATE `cars` SET x = %f WHERE savininkas = '%s' AND kiekis = %i", vehx, GetPlayerNameEx(playerid), v);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET y = %f WHERE savininkas = '%s' AND kiekis = %i", vehy, GetPlayerNameEx(playerid), v);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET z = %f WHERE savininkas = '%s' AND kiekis = %i", vehz, GetPlayerNameEx(playerid), v);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET a = %f WHERE savininkas = '%s' AND kiekis = %i", veha, GetPlayerNameEx(playerid), v);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET `lock` = '%i' WHERE `savininkas` = '%s' AND' `kiekis` = '1'", vInfo[vid1][lock], GetPlayerNameEx(playerid));
		mysql_query(query);
		mysql_free_result();
	}
	
	if(pInfo[playerid][m2id] != 0)
	{
	    new Float:vehx, Float:vehy, Float:vehz, Float:veha, vid2;
		GetVehiclePos(pInfo[playerid][m2id], vehx, vehy, vehz);
		GetVehicleZAngle(pInfo[playerid][m2id], veha);
		vid2 = pInfo[playerid][m2id];
		MySQLCheck();
		format(query, sizeof(query), "UPDATE `cars` SET x = %f WHERE savininkas = '%s' AND kiekis = %i", vehx, GetPlayerNameEx(playerid), d);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET y = %f WHERE savininkas = '%s' AND kiekis = %i", vehy, GetPlayerNameEx(playerid), d);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET z = %f WHERE savininkas = '%s' AND kiekis = %i", vehz, GetPlayerNameEx(playerid), d);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET a = %f WHERE savininkas = '%s' AND kiekis = %i", veha, GetPlayerNameEx(playerid), d);
		mysql_query(query);
		format(query, sizeof(query), "UPDATE `cars` SET `lock` = '%i' WHERE `savininkas` = '%s' AND `kiekis` = '2'", vInfo[vid2][lock], GetPlayerNameEx(playerid));
		mysql_query(query);
		mysql_free_result();
	}
And in MySQL log i get this:
Код:
[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET x = -179.247222 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 1) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET y = 1222.178588 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 1) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET z = 19.306741 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 1) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET a = 198.525039 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 1) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET `lock` = '2' WHERE `savininkas` = 'Cristiano_Fernandes' AND' `kiekis` = '1') - An error has occured. (Error ID: 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 '1'' at line 1)

[17:51:07] >> mysql_free_result( Connection handle: 1 )

[17:51:07] CMySQLHandler::FreeResult() - The result is already empty.

[17:51:07] >> mysql_reconnect( Connection handle: 1 )

[17:51:07] CMySQLHandler::Ping() - Connection is still alive.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET x = -171.474334 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 2) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET y = 1214.454956 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 2) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET z = 19.405532 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 2) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET a = 271.850555 WHERE savininkas = 'Cristiano_Fernandes' AND kiekis = 2) - Successfully executed.

[17:51:07] >> mysql_query( Connection handle: 1 )

[17:51:07] CMySQLHandler::Query(UPDATE `cars` SET `lock` = '2' WHERE `savininkas` = 'Cristiano_Fernandes' AND `kiekis` = '2') - Successfully executed.
Why I get error in this line:
Код:
format(query, sizeof(query), "UPDATE `cars` SET `lock` = '%i' WHERE `savininkas` = '%s' AND' `kiekis` = '1'", vInfo[vid1][lock], GetPlayerNameEx(playerid));
and this line is correct:
Код:
format(query, sizeof(query), "UPDATE `cars` SET `lock` = '%i' WHERE `savininkas` = '%s' AND `kiekis` = '2'", vInfo[vid2][lock], GetPlayerNameEx(playerid));
Reply
#2

Don't wrap your integers in quotes.

pawn Код:
format(query, sizeof(query), "UPDATE `cars` SET `lock` = %i WHERE `savininkas` = '%s' AND `kiekis` = 2", vInfo[vid2][lock], GetPlayerNameEx(playerid));
Also escape your strings, unless you want your database ravished.
Reply
#3

now i get this error:
Код:
[18:01:21] CMySQLHandler::Query(UPDATE `cars` SET `lock` = 2 WHERE `savininkas` = 'Cristiano_Fernandes' AND' `kiekis` = 1) - An error has occured. (Error ID: 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 '' `kiekis` = 1' at line 1)
Reply
#4

There is a random quote after AND in your last query. SQL queries can't contain random syntax breaking characters, or they will - you guessed it - break.
Reply
#5

Sorry My bad english and I don't understant, can you show me how i can make it correct.
Reply
#6

pawn Код:
format(query, sizeof(query), "UPDATE `cars` SET a = %f WHERE savininkas = '%s' AND kiekis = %i", veha, GetPlayerNameEx(playerid), v);
mysql_query(query);
>>>format(query, sizeof(query), "UPDATE `cars` SET `lock` = '%i' WHERE `savininkas` = '%s' AND' `kiekis` = '1'", vInfo[vid1][lock], GetPlayerNameEx(playerid));
mysql_query(query);
mysql_free_result();
Line marked with >>>, there is
Quote:

`savininkas` = '%s' AND' `kiekis`

should be
Quote:

`savininkas` = '%s' AND `kiekis`

Reply
#7

Damnit. Epic fail. Verry thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)