CMD:changename(playerid, params[])
{
new targetid,name[128], query[256];
if(pInfo[playerid][pAdminLevel] >= 5)
{
if(sscanf(params, "us", targetid, name)) return SendClientMessage(playerid,-1,""chat" /changename [playerid] [new name]");
else if(!IsPlayerConnected(targetid))SendClientMessage(playerid,COLOR_RED,"Error: Player is not connected!");else
{
// new string[128],
new n[MAX_PLAYER_NAME];
GetPlayerName(targetid,n,sizeof(n));
SetPlayerName(targetid,name);
format(query, sizeof(query), "UPDATE `users` SET `name` = '%s' WHERE `name` = %s", name, n);
SetPlayerName(targetid, name);
SendClientMessage(targetid, COLOR_RED,"You name has been changed. please re-loggin now.");
new DBResult:dbrResult = db_query(g_dbKeptAlive, query);
db_free_result(dbrResult);
}
}
return 1;
}
@edit
Vocк tб armazenando o valor de um update? Este valor deve ser armazenado numa seleзгo e nгo em uma atualizaзгo. Remova o Resultado da pesquisa, pois nгo vai retornar um valor correto, pois como eu disse, vc nгo tб efetuando uma seleзгo na base de dados. |
Nгo entendi muito bem nгo...
@edit pera tipo isso ? format(query, sizeof(query), "SELECT `users` SET `name` = '%s' WHERE `name` = %s", name, n); |
format(query, sizeof(query), "UPDATE `users` SET `name` = '%s' WHERE `name` = %s", name, n); new DBResult:dbrResult = db_query(g_dbKeptAlive, query); db_free_result(dbrResult);
format(query, sizeof(query), "UPDATE `users` SET `name` = '%s' WHERE `name` = %s", name, n); db_query(g_dbKeptAlive, query);
Nгo, nгo...
Isso: Код:
format(query, sizeof(query), "UPDATE `users` SET `name` = '%s' WHERE `name` = %s", name, n); new DBResult:dbrResult = db_query(g_dbKeptAlive, query); db_free_result(dbrResult); Assim deve bastar! Код:
format(query, sizeof(query), "UPDATE `users` SET `name` = '%s' WHERE `name` = %s", name, n); db_query(g_dbKeptAlive, query); |
format(query, sizeof(query), "UPDATE `users` SET `name` = '%s' WHERE `name` = '%s'", name, n);
Esqueceu de colocar o ъltimo %s entre duas aspas simples:
Код:
format(query, sizeof(query), "UPDATE `users` SET `name` = '%s' WHERE `name` = '%s'", name, n); |
CMD:changename(playerid, params[])
{
new targetid, newname[24], query[256];
if(pInfo[playerid][pAdminLevel] >= 5) {
if(sscanf(params, "ds[24]", targetid, newname)) return SendClientMessage(playerid,-1,""chat" /changename [playerid] [new name]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"Error: Player is not connected!");
new n[MAX_PLAYER_NAME];
GetPlayerName(targetid, n, sizeof(n));
SetPlayerName(targetid, newname);
SendClientMessage(targetid, COLOR_RED,"You name has been changed. please re-loggin now.");
new DBResult:dbrResult = db_query(g_dbKeptAlive, query);
format(szQuery, sizeof(szQuery), "UPDATE `users` SET `name` = '%s' WHERE `name` = '%s'", DB_Escape(newname), n);
db_free_result(dbrResult);
}
return 1;
}
PHP код:
|
CMD:changename(playerid, params[]) { new targetid, newname[24], query[256]; if(pInfo[playerid][pAdminLevel] >= 5) { if(sscanf(params, "ds[24]", targetid, newname)) return SendClientMessage(playerid,-1,""chat" /changename [playerid] [new name]"); if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"Error: Player is not connected!"); new n[MAX_PLAYER_NAME]; GetPlayerName(targetid, n, sizeof(n)); SetPlayerName(targetid, newname); SendClientMessage(targetid, COLOR_RED,"You name has been changed. please re-loggin now."); format(szQuery, sizeof(szQuery), "UPDATE `users` SET `name` = '%s' WHERE `name` = '%s'", DB_Escape(newname), n); db_query(g_dbKeptAlive, query); } return 1; }