BlueG MySQL Error- Setting a password
#1

Hey,

So I've got this code that allows admins to change a players password, whilst offline in case they have forgotten it, now atm it recognises the name you type, and identifies if the account exists or not, however I'm getting a weird mysql log, error which I can't for the life of me work out why it won't process the query, any help appreciated.

Код:
public OnAccountSetPass(playerid,newpass[], name[])
{
	new query[512],string[128];
	if(!cache_num_rows())
	{
		return SendClientMessage(playerid, COLOR_RED, "Invalid Account Name");
	}
	else
	{
		mysql_format(mysql,query, sizeof(query), "UPDATE Users SET pPass='%s' WHERE Name = '%s'",newpass,name);
		mysql_tquery(mysql, query,"", "");
		format(string,sizeof(string),"Admin Log: %s has changed %s's password",GetName(playerid),name);
		ABroadCast(COLOR_ADMIN,string,1);
	}
	return 1;
}
The public function is also forwarded.

Код:
CMD:asetpass(playerid,params[])
{
	new Query[128],name,password[129];
	if(PlayerInfo[playerid][pAdmin] < 5) return 0;
	if(sscanf(params,"s[30]s[16]",name,params)) return SendClientMessage(playerid,-1,"/asetpass [Name] [New Password]");
	if(strlen(params) < 5) return SendClientMessage(playerid,-1,"The password must be longer than 5 characters");
	WP_Hash(password,sizeof(password),params);
	mysql_format(mysql, Query, sizeof(Query), "SELECT * FROM Users WHERE Name = '%s' LIMIT 1",name);
	mysql_tquery(mysql, Query, "OnAccountSetPass", "ss",password,name);
	return 1;
}
Also table & field names are correct.

Error Log
Код:
[20:16:30] [DEBUG] Calling callback "OnAccountSetPass"..
[20:16:30] [DEBUG] cache_get_row_count - connection: 1
[20:16:30] [DEBUG] mysql_format - connection: 1, len: 512, format: "UPDATE Users SET pPass='%s' WHERE Name = '%s'"
[20:16:30] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE Users SET pPass='DSELECT * FROM Users WHERE Name = 'Dan' ", callback: "(null)", format: "(null)"
[20:16:30] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[20:16:30] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[20:16:30] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Dan' LIMIT 1' WHERE Name = ''' at line 1
[20:16:30] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError
Thanks in advance.
Reply
#2

Quote:

"UPDATE Users SET pPass='DSELECT * FROM Users WHERE Name = 'Dan' "

That's a mangled query.

pawn Код:
new Query[128],name,password[129];
You forgot that "name" is a string as well, now you are reading random memory chunk.
Reply
#3

Thanks man, that sorted it, repped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)