SA-MP Forums Archive
Proublems with MySQL query - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Proublems with MySQL query (/showthread.php?tid=150591)



Proublems with MySQL query - hanzen - 26.05.2010

Well I have a problem inserting things to MySQL. This is the code:
Код:
	SetPlayerInterior(playerid, PlayerInfo[playerid][pInt]);
	format(query, sizeof(query), "INSERT INTO players (money, level, admin, interior, bank) VALUES ('%d', '%d', '%d', '%d', '%d')",PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pInt], PlayerInfo[playerid][pName], PlayerInfo[playerid][pBank]);



Re: Proublems with MySQL query - Kyosaur - 26.05.2010

more info please?


Re: Proublems with MySQL query - hanzen - 26.05.2010

Sorry, managed to post wrong lines.
Код:
	new query[256];
	format(query, sizeof(query), "INSERT INTO players (money, level, admin, interior, bank) VALUES ('%d', '%d', '%d', '%d', '%d')",PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pInt], PlayerInfo[playerid][pName], PlayerInfo[playerid][pBank]);
	mysql_query(query, SQLPtr);



Re: Proublems with MySQL query - woot - 26.05.2010

No, you managed to not-tell us what the issue is.


Re: Proublems with MySQL query - Kyosaur - 26.05.2010

Quote:
Originally Posted by hanzen
Sorry, managed to post wrong lines.
Код:
	new query[256];
	format(query, sizeof(query), "INSERT INTO players (money, level, admin, interior, bank) VALUES ('%d', '%d', '%d', '%d', '%d')",PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pInt], PlayerInfo[playerid][pName], PlayerInfo[playerid][pBank]);
	mysql_query(query, SQLPtr);
Two things i noticed from that code: Specifier count doesnt match the variable count. Also, your using the wrong type of specifiers. pName and pAdmin should be strings (erm well pName for sure).




Re: Proublems with MySQL query - hanzen - 26.05.2010

Ok.. OnPlayerUpdate() is suppose to update som data in the database. I run this, but it wont insert into the table.
Код:
	new query[256];
	format(query, sizeof(query), "UPDATE players SET money = '%d', level = '%d', admin = '%d', skin = '%d', bank = '%d' WHERE name = '%s'",PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pBank]), PlayerInfo[playerid][pName];
	mysql_query(query, SQLPtr);



Re: Proublems with MySQL query - Kyosaur - 26.05.2010

Quote:
Originally Posted by hanzen
Ok.. OnPlayerUpdate() is suppose to update som data in the database. I run this, but it wont insert into the table.
Код:
	new query[256];
	format(query, sizeof(query), "UPDATE players SET money = '%d', level = '%d', admin = '%d', skin = '%d', bank = '%d' WHERE name = '%s'",PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pBank]), PlayerInfo[playerid][pName];
	mysql_query(query, SQLPtr);
Dont use OnPlayerUpdate to save stats, its called way to frequently.


Edit:

The problem with the second one is that the ")" is in the wrong place.


BTW: is "PlayerInfo[playerid][pAdmin]" a string or an integer? Im thinking its a string, as you already have a variable for admin level, so change the corresponding %d's into %s's.



Re: Proublems with MySQL query - hanzen - 26.05.2010

Seems like I got it working with changing the ")". Still it doesnt enter the info correctly.


Money is suppose to be 20000.
Level is correct.
Admin is suppose to be 5.
Skin is suppose to be 104.
Bank is suppose to be 0.



Re: Proublems with MySQL query - hanzen - 26.05.2010

Well.. it keeps inserting the info to random fields.