I don't see what I'm doing wrong...
#1

Hi guys. I am trying to "log" all things that admins do in-game and put it in a table in my MySQL database. I keep getting an error with this piece of code though:

pawn Код:
stock AdminLog(adminname[], playername[], action[], reason[])
{
    new hour, minute, second, year, month, day, time[9];
    gettime(hour, minute, second);
    getdate(year, month, day);

    format(Query, sizeof(Query), "INSERT INTO `Admin Logs` (`AdminName`, `PlayerName`, `Action`, `Reason`, `Date`, `Time`) VALUES('%s', '%s', '%s', '%s', %d/%d/%d, %d:%d:%d)", adminname, playername, action, reason, month, day, year, hour, minute, second);
    mysql_query(Query);
}
This is the error:

Код:
[17:10:45] CMySQLHandler::Query(INSERT INTO `Admin Logs` (`AdminName`, `PlayerName`, `Action`, `Reason`, `Date`, `Time`) VALUES('RealCop228', 'RealCop228', 'Gave Weapon(s)', 'N/A', 11/12/2010, 17:10:45)) - An error has occured. (Error ID: 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 ':10:45)' at line 1)
I am using G-Stylez MySQL plugin.
Reply
#2

Your problem would consist at trying to insert "%d/%d/%d" - MySQL syntax is different from file functions.

Firstly, make sure that the Date and Time options are strings, then do something like the following:
pawn Код:
format(string, 20, "%d/%d/%d", month, day, year);
format(string2, 20, "%d:%d:%d", hour, minute, second);
format(Query, sizeof(Query), "INSERT INTO `Admin Logs` (`AdminName`, `PlayerName`, `Action`, `Reason`, `Date`, `Time`) VALUES('%s', '%s', '%s', '%s', '%s', '%s')", adminname, playername, action, reason, string, string2);
Better yet, you could use the default time and date functions included in MySQL - look them up.
Reply
#3

Quote:
Originally Posted by Grim_
Посмотреть сообщение
Your problem would consist at trying to insert "%d/%d/%d" - MySQL syntax is different from file functions.

Firstly, make sure that the Date and Time options are strings, then do something like the following:
pawn Код:
format(string, 20, "%d/%d/%d", month, day, year);
format(string2, 20, "%d:%d:%d", hour, minute, second);
format(Query, sizeof(Query), "INSERT INTO `Admin Logs` (`AdminName`, `PlayerName`, `Action`, `Reason`, `Date`, `Time`) VALUES('%s', '%s', '%s', '%s', '%s', '%s')", adminname, playername, action, reason, string, string2);
Better yet, you could use the default time and date functions included in MySQL - look them up.
I tried doing it with strings like you did, but no difference. I will look into the default time and date functions for MySQL.

EDIT: I have been looking for something, but I only found a MySQL manual which really didn't explain anything to me. Could somebody be of some assistance?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)