I cant find the mysql error
#1

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

Update your MYSQL query string's size.

new query[5000]; for example.
Reply
#3

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

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);

}
Reply
#5

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

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

TIP: Escape strings in mysql to avoid SQL injection.
Reply
#6

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)