Mysql Trying 3 cases
#1

pawn Код:
mysql_format(g_SQL, string, sizeof(string), "SELECT * FROM `bans` WHERE `bannick`='%e' OR `banip`='%e' AND banned=true LIMIT 1", PlayerInfo[playerid][pUserName],PlayerInfo[playerid][pIP]);
    mysql_pquery(g_SQL, string, "CheckPlayerBan", "d", playerid);
How could i do to check for the ip or that banned nick but where the banned should be true it's a boolen on database.
As even if i will remove my bans it won't remove this record.
Reply
#2

Код:
"SELECT * FROM `bans` WHERE (`bannick`='%e' OR `banip`='%e') AND `banned`='1' LIMIT 1"
(not sure if the added brackets are needed, just is cleaner to read, the actual fix was expecting banned to be '1' instead of true)
Reply
#3

thanks for this but another problem occurred
No error in mysql log
pawn Код:
format(string,sizeof(string),"NOW()+%d",60*60*24*days);
    print(string);
mysql_format(g_SQL, string, sizeof(string), "UPDATE bans SET banby='%e',bannick='%e',banip='%e',banon=NOW(),banexpire=%s,banned=%d,banperma=%d WHERE banid=%d LIMIT 1",BanInfo[ServerInfo[sCurrentBanID]][BanBy],BanInfo[ServerInfo[sCurrentBanID]][BanNick],BanInfo[ServerInfo[sCurrentBanID]][BanIP],string,BanInfo[ServerInfo[sCurrentBanID]][Banned],BanInfo[ServerInfo[sCurrentBanID]][BanPerma],ServerInfo[sCurrentBanID]);
    print(string);
    mysql_tquery(g_SQL, string);
This won't just update, nothing there but there is code after this which gets executed this means this doesn't crash.
This is the log, i just used some print functions
Код:
[20:09:45] NOW()+604800
[20:09:45] UPDATE bans SET banby='Sasuke_Uchiha',bannick='Sasuke_Uchiha',banip='127.0.0.1',banon=NOW(),banexpire=NOW()+604800,banned=1,banperma=0 WHERE banid=6 LIMIT 1
Reply
#4

Why are you using %e.....

You're calling strings AND Integers...
YET
You refer to everything as... %e....

Strings = '%s'

Integers = %d

Flots = %f


so why are you using %e... For everything

And again as above..
You're telling it up UPDATE... that exact column..
where banid=6
So it will only update fields that have "banid" as 6
Reply
#5

@Prokill911; the %e is some automatically escaped version of the variable, not a fan of it either but apparently its common practice, mysql_format wiki page says:
Код:
Placeholder | Meaning
%e   <<<<   | Escapes data directly without the need to call mysql_escape_string() before
%s          | Inserts a string.
... etc ...
@AroseKhanNiazi; like i just explained in your other thread, your better off switching to timestamps anyway :P
Reply
#6

Okay just converted still not working :/
debug
pawn Код:
[23:27:32] UPDATE bans SET banby='Sasuke_Uchiha',bannick='Sasuke_Uchiha',banip='127.0.0.1',banon=UNIX_TIMESTAMP(),banexpire=UNIX_TIMESTAMP()+432000,banned=1,banperma=0,bandate=NOW() WHERE banid=7 LIMIT 1
code
pawn Код:
mysql_format(g_SQL, string, sizeof(string), "UPDATE bans SET banby='%e',bannick='%e',banip='%e',banon=UNIX_TIMESTAMP(),banexpire=UNIX_TIMESTAMP()+%d,banned=%d,banperma=%d,bandate=NOW() WHERE banid=%d LIMIT 1",BanInfo[ServerInfo[sCurrentBanID]][BanBy],BanInfo[ServerInfo[sCurrentBanID]][BanNick],BanInfo[ServerInfo[sCurrentBanID]][BanIP],BanInfo[ServerInfo[sCurrentBanID]][BanExpire],BanInfo[ServerInfo[sCurrentBanID]][Banned],BanInfo[ServerInfo[sCurrentBanID]][BanPerma],ServerInfo[sCurrentBanID]);
    print(string);
Reply
#7

Dont use the UNIX_TIMESTAMP() function in sa-mp, just use gettime() (sa-mp's timestamp function)

Like so:
Код:
new string[128],
    curr_timestamp = gettime(); // ADDED
    
mysql_format(g_SQL, string, sizeof(string),
    "UPDATE bans SET banby='%e',bannick='%e', banip='%e', banon=%d, banexpire=%d, banned=%d, banperma=%d, bandate=NOW() WHERE banid=%d LIMIT 1", // UPDATED
    BanInfo[ServerInfo[sCurrentBanID]][BanBy],
    BanInfo[ServerInfo[sCurrentBanID]][BanNick],
    BanInfo[ServerInfo[sCurrentBanID]][BanIP],
    curr_timestamp, // ADDED
    (curr_timestamp+BanInfo[ServerInfo[sCurrentBanID]][BanExpire]), // UPDATED
    BanInfo[ServerInfo[sCurrentBanID]][Banned],
    BanInfo[ServerInfo[sCurrentBanID]][BanPerma],
    ServerInfo[sCurrentBanID]
);
print(string);
Reply
#8

just asking will it be same time on mysql database as gettime as unban will work with mysql database.
Reply
#9

Yes, both are based on the same system clock (assuming the sa-mp server and the database server are on the same machine)
Reply
#10

pawn Код:
new unbanon=gettime()+BanInfo[ServerInfo[sCurrentBanID]][BanExpire];
    mysql_format(g_SQL, string, sizeof(string),
    "UPDATE bans SET banby='%e',bannick='%e', banip='%e',banexpire=%d, banned=%d, banperma=%d, bandate=NOW() WHERE banid=%d LIMIT 1",
    BanInfo[ServerInfo[sCurrentBanID]][BanBy],
    BanInfo[ServerInfo[sCurrentBanID]][BanNick],
    BanInfo[ServerInfo[sCurrentBanID]][BanIP],
    unbanon,
    BanInfo[ServerInfo[sCurrentBanID]][Banned],
    BanInfo[ServerInfo[sCurrentBanID]][BanPerma],
    ServerInfo[sCurrentBanID]);
even did this code still no error in log and not even updating
Tried it setting banexpire type as timestamp and bigint both way it won't work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)