SA-MP Forums Archive
I cant find the mysql 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: I cant find the mysql error (/showthread.php?tid=572801)



I cant find the mysql error - Zloto - 01.05.2015

Code:

Код:
format(query, sizeof(query), "UPDATE players SET Username = '%s', Password = '%s', PlayerX = %f, PlayerY = %f, PlayerZ = %f WHERE Username = `%s`", pName, Player[playerid][Password], Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], pName);
Error:

Код:
[MySQL] Error (0): Failed to exeute query. 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 'WHER' at line 1.



Re: I cant find the mysql error - DRCharlie - 02.05.2015

Update your MYSQL query string's size.

new query[5000]; for example.


Re: I cant find the mysql error - MP2 - 02.05.2015

Quote:
Originally Posted by DRCharlie
Посмотреть сообщение
Update your MYSQL query string's size.

new query[5000]; for example.
That is way over the top. The max he would need is, by my calculations, assuming max password is 64 chars and username is MAX_PLAYER_NAME: 243 characters. Do 256 should do it, to round it off.

Also, you should look in to using Primary keys and Indexing.


Re: I cant find the mysql error - Zloto - 02.05.2015

Thanks! When I seted it to 256 it's ok. But now i get the following error...
Код:
[14:09:10] Number of vehicle models: 0
[14:09:28] Incoming connection: IP:PORT
[14:09:29] [join] Kemal3 has joined the server (0:IP)
[14:09:39] [MySQL] Error (0): Failed to exeute query. Unknown column 'Kemal3' in 'where clause'.
[14:09:39] Player ID 0 has been saved
[14:09:39] [part] Kemal3 has left the server (0:1)
Код:
stock SavePlayer(playerid){
	new query[256], pName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pName, sizeof(pName));
	
	GetPlayerPos(playerid, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
	
	format(query, sizeof(query), "UPDATE `players` SET Username = '%s', Password = '%s', PlayerX = %f, PlayerY = %f, PlayerZ = %f WHERE Username = `%s`", pName, Player[playerid][Password], Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], pName);
	mysql_query(query);
	printf("Player ID %d has been saved", playerid, pName);

}



Re: I cant find the mysql error - Konstantinos - 02.05.2015

"... WHERE Username = `%s`"

Change to '%s' instead because it reads it as the field otherwise.

TIP: Escape strings in mysql to avoid SQL injection.


Re: I cant find the mysql error - Zloto - 02.05.2015

Thanks! I'm new to the pawn started it 3 days ago..

So i will need to remove the convert to string from those lanes?

Код:
      mysql_fetch_field_row(query, "PlayerX"); Player[playerid][Position[0] = floatstr(query);
		mysql_fetch_field_row(query, "PlayerY"); Player[playerid][Position[1] = floatstr(query);
		mysql_fetch_field_row(query, "PlayerZ"); Player[playerid][Position[2] = floatstr(query);



Re: I cant find the mysql error - joedyjoe - 02.05.2015

Quote:
Originally Posted by Zloto
Посмотреть сообщение
Thanks! I'm new to the pawn started it 3 days ago..

So i will need to remove the convert to string from those lanes?

Код:
      mysql_fetch_field_row(query, "PlayerX"); Player[playerid][Position[0] = floatstr(query);
		mysql_fetch_field_row(query, "PlayerY"); Player[playerid][Position[1] = floatstr(query);
		mysql_fetch_field_row(query, "PlayerZ"); Player[playerid][Position[2] = floatstr(query);
Yep.


Re: I cant find the mysql error - Konstantinos - 02.05.2015

Why would you do that? Don't you want to load the position of the player?

Is it because I mentioned about escaping strings? If so, that has nothing to do with it: https://sampwiki.blast.hk/wiki/MySQL#mys..._escape_string