MySQL syntax error
#1

Код:
forward OfflineBanCheck(adminid, reason[]);
public OfflineBanCheck(adminid, reason[])
{
	new rows, fields;
    cache_get_data(rows, fields, mysql);

    if(rows)
    {
    	new ip[16], name[MAX_PLAYER_NAME], seconds, query[144], string[128];

    	cache_get_field_content(0, "Name", name, mysql, MAX_PLAYER_NAME);
		cache_get_field_content(0, "IP", ip);
		seconds = (gettime()+604800);
        
    	mysql_format(mysql, query, sizeof(query), "INSERT INTO `bans` (`Player`, `IP`, `Reason`, `Unban date`, `Banned by`) VALUES ('%e', '%e', '%e', '%d', '%e')", name, ip, reason, seconds, Name(adminid));
    	mysql_tquery(mysql, query, "", "");

    	SendClientMessage(adminid, C_LRED, "Player banned!");

    } else return SendClientMessage(adminid, C_LRED, "Player not found!");
	return 1;
}
And error:

Код:
[08:19:12] [DEBUG] mysql_tquery - scheduling query "INSERT INTO `bans` (`Player`, `IP`, `Reason`, `Unban date`, `Banned by`) VALUES ('noob123', '94.123.200.55', 'Reason', '1440245952', '"..
[08:19:12] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[08:19:12] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[08:19:12] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[08:19:12] [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 ''' at line 1
[08:19:12] [DEBUG] CMySQLQuery::Execute[()] - error will be triggered in OnQueryError
[08:19:12] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[08:19:12] [DEBUG] Calling callback "OnQueryError"..
Cant see the mistake here, hmm?
Reply
#2

Hmm I really cant spot a mistake.
Reply
#3

Maybe query size is too small?
Reply
#4

You don't need to put integer values inside quotation marks:

pawn Код:
'%d'
should just be
pawn Код:
%d
Reply
#5

Quote:
Originally Posted by finelaq
Посмотреть сообщение
Maybe query size is too small?
This, mostly.

However, take note that in a properly normalized database a player's name only appears once in the entire database and all tables that need the information have to reference that one table. This makes it so that if you change a player's name you only need to change it one place only and thus avoid data corruption.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)