MySQL saving
#1

ok im working on some MySql project..

i have managed toconnect the server with my websites MySql
but now this
pawn Код:
mysql_function_query(connectionHandle, "CREATE TABLE IF NOT EXISTS memmbers(Username VARCHAR(24), Money INT(20), Score INT(20), IP VARCHAR(16) , TOS VARCHAR(16) )",false,"OnQueryFinish","","");
new pname[24], IP[16];
GetPlayerName(playerid, pname, 24);
GetPlayerIp(playerid, IP, 16);
//dont worry about the TStr
mysql_function_query(connectionHandle,"INSERT INTO memmbers (Username, Money, Score, IP, TOS) VALUES ('%s','%d','%d','%s','%s')",false,"OnQueryFinish","siiss",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
i debuged the print out from OnQueryFinish it all displays fine but then after i check the MySql database this is what comes up

Код:
Username 	Money 	Score 	IP 	TOS
 	%s 	0 	0 	%s 	0
Reply
#2

mysql_format + mysql_function_query
Reply
#3

Hello.

You need to format your query BEFORE you use it in mysql_function_query. Right now, your query is doing this:

Username=%s
Money=%d
Score=%d
IP=%s
TOS=%s


You need to format your string before this point like this:
pawn Код:
new query[256];
mysql_format(connectionHandle,query,"INSERT INTO memmbers (Username, Money, Score, IP, TOS) VALUES ('%s','%d','%d','%s','%s')",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
//Where connectionHandleis the ID of your connection to the mysql database
And then you can run the query:
pawn Код:
mysql_function_query(connectionHandle,query,false,"OnQueryFinish","siiss",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
Reply
#4

Quote:
Originally Posted by Pedro_Miranda
Посмотреть сообщение
mysql_format + mysql_function_query
Quote:
Originally Posted by Hawky133
Посмотреть сообщение
Hello.

You need to format your query BEFORE you use it in mysql_function_query. Right now, your query is doing this:

Username=%s
Money=%d
Score=%d
IP=%s
TOS=%s


You need to format your string before this point like this:
pawn Код:
new query[256];
mysql_format(connectionHandle,query,"INSERT INTO memmbers (Username, Money, Score, IP, TOS) VALUES ('%s','%d','%d','%s','%s')",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
//Where connectionHandleis the ID of your connection to the mysql database
And then you can run the query:
pawn Код:
mysql_function_query(connectionHandle,query,false,"OnQueryFinish","siiss",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
ok i know what iv done wrong
i didnt event know that function before it was a simple format
anyways tnx
Reply
#5

Also, make sure you aren't using insert to save because you will end up creating multiple entries for one user. This means that when you pull the data back (for a login) you could end up pulling an entry that is not the most recent.
Reply
#6

yes i know im only using INSERT for the first time the player registers the rest i use UPDATE
i have done more then enought test and can say all works fine
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)