Ban Command
#1

Hello mates i have a small problem with my code here. The problem is that it doesnt insert any values on bans table!! its empty
pawn Код:
CMD:ban(playerid,params[])
    {
        new pid,reason[70],string[120],string2[140], Query[240],pIP[16];
         new year, month, date;
         GetPlayerIp(pid,pIP,sizeof(pIP));
        getdate(year, month, date);
        printf("%02d:%02d:%02d", year, month, date);
        new Seconds = getdate();
        printf("The player %s has been banned at: %d", GPN(pid),Seconds);
        if(pinfo[playerid][Admin] < 3) return 0;
        if(pinfo[playerid][Admin] < pinfo[pid][Admin]) return SendClientMessage(playerid,COLOR_RED," (ERROR): You can't ban a higher level admin!");
        if(sscanf(params,"us[70]",pid,reason)) return SendClientMessage(playerid, COLOR_RED," SERVER : /ban [playerid] [reason]");
        if(pid == INVALID_PLAYER_ID || !IsPlayerConnected(pid)) return ErrorMessages(playerid,2);
        format(string,sizeof(string),"CCNR SYSTEM: %s ( %i ) has been banned from the server. Reason: %s",GPN(pid),pid,reason);
        SendClientMessageToAll(COLOR_PINK,string);
        format(string,sizeof(string),"CCNR SYSTEM: You have been banned from the server. Date: %d / %d / %d Reason: %s",year,month,date,reason);
        SendClientMessage(pid,COLOR_PINK,string2);
        pinfo[pid][Banned] = 1;
        mysql_format(mysql, Query, sizeof(Query), "UPDATE `players` SET `Banned` = '%i' WHERE ID = '%i'", pinfo[pid][Banned], pinfo[pid][ID]);
        //mysql_tquery(mysql, Query);
        mysql_format(mysql, Query, sizeof(Query), "INSET INTO `bans` VALUES ('%s', '%s', '%s', '%s', '%s', '1')",GPN(pid),reason,GPN(playerid),pIP,gettime());
        mysql_tquery(mysql,Query);
        Kick(pid);
       
        return 1;
    }
Could the problem be anywhere else?
Reply
#2

Код:
mysql_format(mysql, Query, sizeof(Query), "INSET INTO `bans` VALUES ('%s', '%s', '%s', '%s', '%s', '1')",GPN(pid),reason,GPN(playerid),pIP,gettime());
you did not name the things you're saving / inserting
PHP код:
mysql_format(mysqlQuerysizeof(Query), "INSET INTO `bans`(`somthing`,`somthing`,`somthing`,`somthing`,`somthing`,`somthing`) VALUES ('%s', '%s', '%s', '%s', '%s', '1')",GPN(pid),reason,GPN(playerid),pIP,gettime()); 
Reply
#3

Quote:
Originally Posted by jlalt
Посмотреть сообщение
Код:
mysql_format(mysql, Query, sizeof(Query), "INSET INTO `bans` VALUES ('%s', '%s', '%s', '%s', '%s', '1')",GPN(pid),reason,GPN(playerid),pIP,gettime());
you did not name the things you're saving / inserting
PHP код:
mysql_format(mysqlQuerysizeof(Query), "INSET INTO `bans`(`somthing`,`somthing`,`somthing`,`somthing`,`somthing`,`somthing`) VALUES ('%s', '%s', '%s', '%s', '%s', '1')",GPN(pid),reason,GPN(playerid),pIP,gettime()); 
Ugh thats true how i forgot that.. thanks jlalt!
Reply
#4

Now it saves all as 0,0,0,0
EDIT:Sorry for double post . Didn't realise!
Reply
#5

Quote:
Originally Posted by vassilis
Посмотреть сообщение
Now it saves all as 0,0,0,0
EDIT:Sorry for double post . Didn't realise!
Well, now it work or?
Reply
#6

Well it inserts values but all with 0 except of last parameter it is 0,0,0,0,1
Reply
#7

Maybe you made your mysql tabels wrong?
Or try to printf(Query);
see result
Reply
#8

It prints the right values :S
pawn Код:
CMD:ban(playerid,params[])
    {
        new pid,reason[70],string[120],string2[140], Query[240],pIP[16];
         new year, month, date;
         GetPlayerIp(pid,pIP,sizeof(pIP));
        getdate(year, month, date);
        printf("%02d:%02d:%02d", year, month, date);
        new Seconds = getdate();
        printf("The player %s has been banned at: %d", GPN(pid),Seconds);
        if(pinfo[playerid][Admin] < 3) return 0;
        if(pinfo[playerid][Admin] < pinfo[pid][Admin]) return SendClientMessage(playerid,COLOR_RED," (ERROR): You can't ban a higher level admin!");
        if(sscanf(params,"us[70]",pid,reason)) return SendClientMessage(playerid, COLOR_RED," SERVER : /ban [playerid] [reason]");
        if(pid == INVALID_PLAYER_ID || !IsPlayerConnected(pid)) return ErrorMessages(playerid,2);
        format(string,sizeof(string),"CCNR SYSTEM: %s ( %i ) has been banned from the server. Reason: %s",GPN(pid),pid,reason);
        SendClientMessageToAll(COLOR_PINK,string);
        format(string,sizeof(string),"CCNR SYSTEM: You have been banned from the server. Date: %d / %d / %d Reason: %s",year,month,date,reason);
        SendClientMessage(pid,COLOR_PINK,string2);
        pinfo[pid][Banned] = 1;
        mysql_format(mysql, Query, sizeof(Query), "UPDATE `players` SET `Banned` = '%i' WHERE ID = '%i'", pinfo[pid][Banned], pinfo[pid][ID]);
        //mysql_tquery(mysql, Query);
        mysql_format(mysql, Query, sizeof(Query), "INSERT INTO `bans` VALUES (`Name` = '%s', `Reason` = '%s',`BannedBy` = '%s',`IP` = '%s', `Date` = '%s', `Status` = '1')",GPN(pid),reason,GPN(playerid),pIP,getdate());
        mysql_tquery(mysql,Query);
        printf(Query);
        Kick(pid);
       
        return 1;
    }
PRINT:
[00:17:10] The player vassilis has been banned at: 314
[00:17:10] INSERT INTO `bans` VALUES (`Name` = 'vassilis', `Reason` = 'test',`BannedBy` = 'vassilis',`IP` = 'Hidden(for security reasons)', `Date` = ':vassilis', `Status` = '1')
[00:17:10] [part] vassilis has left the server (0:2)
Reply
#9

Quote:
Originally Posted by vassilis
Посмотреть сообщение
It prints the right values :S
pawn Код:
CMD:ban(playerid,params[])
    {
        new pid,reason[70],string[120],string2[140], Query[240],pIP[16];
         new year, month, date;
         GetPlayerIp(pid,pIP,sizeof(pIP));
        getdate(year, month, date);
        printf("%02d:%02d:%02d", year, month, date);
        new Seconds = getdate();
        printf("The player %s has been banned at: %d", GPN(pid),Seconds);
        if(pinfo[playerid][Admin] < 3) return 0;
        if(pinfo[playerid][Admin] < pinfo[pid][Admin]) return SendClientMessage(playerid,COLOR_RED," (ERROR): You can't ban a higher level admin!");
        if(sscanf(params,"us[70]",pid,reason)) return SendClientMessage(playerid, COLOR_RED," SERVER : /ban [playerid] [reason]");
        if(pid == INVALID_PLAYER_ID || !IsPlayerConnected(pid)) return ErrorMessages(playerid,2);
        format(string,sizeof(string),"CCNR SYSTEM: %s ( %i ) has been banned from the server. Reason: %s",GPN(pid),pid,reason);
        SendClientMessageToAll(COLOR_PINK,string);
        format(string,sizeof(string),"CCNR SYSTEM: You have been banned from the server. Date: %d / %d / %d Reason: %s",year,month,date,reason);
        SendClientMessage(pid,COLOR_PINK,string2);
        pinfo[pid][Banned] = 1;
        mysql_format(mysql, Query, sizeof(Query), "UPDATE `players` SET `Banned` = '%i' WHERE ID = '%i'", pinfo[pid][Banned], pinfo[pid][ID]);
        //mysql_tquery(mysql, Query);
        mysql_format(mysql, Query, sizeof(Query), "INSERT INTO `bans` VALUES (`Name` = '%s', `Reason` = '%s',`BannedBy` = '%s',`IP` = '%s', `Date` = '%s', `Status` = '1')",GPN(pid),reason,GPN(playerid),pIP,getdate());
        mysql_tquery(mysql,Query);
        printf(Query);
        Kick(pid);
       
        return 1;
    }
PRINT:
[00:17:10] The player vassilis has been banned at: 314
[00:17:10] INSERT INTO `bans` VALUES (`Name` = 'vassilis', `Reason` = 'test',`BannedBy` = 'vassilis',`IP` = '192.168.1.7', `Date` = ':vassilis', `Status` = '1')
[00:17:10] [part] vassilis has left the server (0:2)
The way you are creating that query is not correct, if you use VALUES then you must specify only the values as the name itself says. However, if you want to specify the column names then you have to do it prior.

Like this:

PHP код:
INSERT INTO `bans` (`Name`, `Reason`, `BannedBy`, `IP`, `Status`) VALUES ('%s''%s''%s','%s''%s''1'
Reply
#10

i tried it like that and it doesnt insert the values now at all the bans table is empty eventhough i ban my self..
pawn Код:
[01:09:25] [DEBUG] mysql_format - connection: 1, len: 240, format: "INSERT INTO `bans` (`Name`, `Reason`, `BannedBy`, `IP`, `Status`) VALUES ('%s', '%s', '%s','%s', '%s', '1')"
[01:09:25] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `bans` (`Name`, `Reason`, `BannedBy`, `IP`, `Status`", callback: "(null)", format: "(null)"
[01:09:25] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[01:09:26] [DEBUG] mysql_format - connection: 1, len: 340, format: "UPDATE `players` SET `Admin`=%d, `VIP`=%d, `Money`=%d, `posX`=%f, `posY`=%f, `posZ`=%f,`Score` =%d, `Banned` =%d, `Cuffed` =%d, ..."
[01:09:26] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 318.277 milliseconds
[01:09:26] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
[01:09:26] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[01:09:26] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Ґ', '1')' at line 1
[01:09:26] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError
[01:09:26] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `players` SET `Admin`=5, `VIP`=0, `Money`=0, `posX`=965.8", callback: "(null)", format: "(null)"
[01:09:26] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[01:09:26] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 79.348 milliseconds
[01:09:26] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
THATS MY MYSQL LOG

EDIT: I FIXED IT!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)