PDA

View Full Version : Help with inserts (MYSQL)


Kan
15/04/2014, 08:12 PM
Hello friends! I've a problem with insert a new line at my database.

My script is that:

public OnRconLoginAttempt(ip[], password[], success) {
new
gQuery[200],
gBuf[2][50],
gTime[3],
gDate[3],
gLoop = -1,
gIp[20],
gName[25];
gettime(gTime[0], gTime[1], gTime[2]);
getdate(gDate[0], gDate[1], gDate[2]);
format(gBuf[0], 50, "%02i:%02i:%02i", gTime[0], gTime[1], gTime[2]);
format(gBuf[1], 50, "%02i/%02i/%04i", gDate[2], gDate[1], gDate[0]);
while (++gLoop < MAX_PLAYERS) {
GetPlayerIp(gLoop, gIp, sizeof(gIp));
if (!strcmp(ip, gIp, true)) {
format(gName, 25, getPlayerName(gLoop));
}
}
mysql_format(gDB, gQuery, "insert into rcon_logs (name, ip, pass, hour, date, success) values ('%s', '%s', '%s', '%s', '%s', %i)", gName, ip, password, gBuf[0], gBuf[1], (success) ? 1 : 0);
mysql_function_query(gDB, gQuery, false, "", "");
return 1;
}


In the database looks like this:
http://i.imgur.com/h2R6PT4.png

Someone can help me pls?

Kar
15/04/2014, 08:25 PM
format(gQuery, sizeof(gQuery), "INSERT INTO rcon_logs (name, ip, pass, hour, date, success) VALUES ('%s', '%s', '%s', '%s', '%s', %i)", gName, ip, password, gBuf[0], gBuf[1], (success) ? 1 : 0);
mysql_tquery(gDB, gQuery);

Kan
15/04/2014, 09:28 PM
I'm using mysql r7.

Which is better: mysql r7 or r38?

Vince
16/04/2014, 12:19 AM
Newer is mostly better.

Also, why are you using the 'g' prefix if none of the listed variables (except gDB) are actually globals? This is very good way to confuse people.