SetPlayerInfo function (mysql) doesn't work
#1

The function that will set player data doesn't work, and I don't know why.

Anybody

Код:
SetPlayerInfo(playerid, "language", "1", 0);//Set the language (player data) to 1
Код:
stock SetPlayerInfo(playerid, info[], newinfo[], vartype)
{
	if(vartype){
		format(query, sizeof(query), "UPDATE `users` SET '%s' = '%s' WHERE `username` = '%s'", info, newinfo,PlayerName[playerid]);
	}else{
		format(query, sizeof(query), "UPDATE `users` SET '%s' = '%d' WHERE `username` = '%s'", info, newinfo,PlayerName[playerid]);
	}
	printf("SetPlayerInfo %s", query);
	mysql_query(query);
}
Reply
#2

You're passing it as a string in the format function, when it's supposed to be an integer, you need to use a function like strval. Additionally I would change the SQL syntax slightly, like so:

pawn Код:
stock SetPlayerInfo(playerid, info[], newinfo[], vartype)
{
    if(vartype){
        format(query, sizeof(query), "UPDATE `users` SET %s = '%s' WHERE username = '%s'", info, newinfo,PlayerName[playerid]);
    }else{
        format(query, sizeof(query), "UPDATE `users` SET %s = %d WHERE username = '%s'", info, strval(newinfo),PlayerName[playerid]);
    }
    printf("SetPlayerInfo %s", query);
    mysql_query(query);
}
Reply
#3

Thanks!

RED text part works now, but the blue text part doesn't work.

Код:
stock SetPlayerInfo(playerid, info[], newinfo[], vartype)
{
    if(vartype){
        format(query, sizeof(query), "UPDATE `users` SET %s = '%s' WHERE username = '%s'", info, newinfo,PlayerName[playerid]);
    }else{
        format(query, sizeof(query), "UPDATE `users` SET %s = %d WHERE username = '%s'", info, strval(newinfo),PlayerName[playerid]);
    }
    printf("SetPlayerInfo %s", query);
    mysql_query(query);
}
Any idea?
Reply
#4

What are you using to test it for the blue part?
Reply
#5

Check the MySQL logs?
Reply
#6

From my knowledge, this should fix it.

Код:
stock SetPlayerInfo(playerid, info[], newinfo[], vartype)
{
    if(vartype){
        format(query, sizeof(query), "UPDATE `users` SET `%s` = '%s' WHERE username = '%s'", info, newinfo,PlayerName[playerid]);
    }else{
        format(query, sizeof(query), "UPDATE `users` SET `%s` = %d WHERE username = '%s'", info, strval(newinfo),PlayerName[playerid]);
    }
    printf("SetPlayerInfo %s", query);
    mysql_query(query);
}
Reply
#7

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
What are you using to test it for the blue part?
SetPlayerInfo(playerid, "reasonofwarn1", "hacks", 1);

My MySQL log file give this error:

[11:11:14] CMySQLHandler::Query(UPDATE `users` SET `secretquestionanwser` = 'henk' WHERE username = '[VLA]Battleman') - An error has occured. (Error ID: 1054, Unknown column 'secretquestionanwser' in 'field list')

[11:11:16] >> mysql_query( Connection handle: 1 )

Reply
#8

You spelled it differently in table and in the query, in the table it is "answer", which is correct, and in the query it is "anwser", which is wrong, so that column does not exist
Reply
#9

Lol stupid :P

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)