Proublems with MySQL query
#1

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

more info please?
Reply
#3

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

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

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

Reply
#6

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)