Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Not added to mysql

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    Not added to mysql

    Hi all,

    I want to make a banlist using mysql

    Code:
    guidbanplayer(admin, reason, id, guid)
    {   
    	maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO ban_guid_sd (guid, name, reason, admin) VALUES (" + guid + ", " + maps\mp\gametypes\_mysql::stripString(self.name) + "," + maps\mp\gametypes\_mysql::stripString(reason) + "," + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + ")");
    	printf("GUID ban added to database2!\n");
    	printf("guid "+guid+ "\n");
    	printf("name "+maps\mp\gametypes\_mysql::stripString(self.name)+ "\n");
    	printf("reason "+maps\mp\gametypes\_mysql::stripString(reason)+ "\n");
    	printf("admin "+maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"])+ "\n");
    
    }
    the table name is ban_guid_sd
    the printf are shown correct

    However, the record is not added to the table.
    Im connected to the database
    Code:
    initMySQL(host, user, pass, db, port)
    {
        mysql = mysql_init();
        ret = mysql_real_connect(mysql, host, user, pass, db, port);
        if(!ret)
        {
            printf("errno=" + mysql_errno(mysql) + " error= " + mysql_error(mysql) + "\n");
            mysql_close(mysql);
            return undefined;
        }
    	else 
    		printf("Connected to database!\n");
        return mysql;
    }
    I see the message "Connected to database"

    What is wrong?

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Init your async mysql, not just your mysql.

    Also: put ' around your strings.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  3. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (22nd June 2016)

  4. #3
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by IzNoGoD View Post
    Init your async mysql, not just your mysql.

    Also: put ' around your strings.
    Already done
    Code:
    initAsyncMySQL(host, user, pass, db, port)
    {
        mysql_async_initializer(host, user, pass, db, port, 4);
        level.mysqlAsync = [];
        thread loopAsyncMySQL();
    }
    And do you mean this?
    Code:
    maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO ban_guid_sd ('guid', 'name', 'reason', 'admin') VALUES (" + guid + ", " + maps\mp\gametypes\_mysql::stripString(self.name) + "," + maps\mp\gametypes\_mysql::stripString(reason) + "," + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + ")");

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    no, like this
    Code:
    maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO ban_guid_sd (guid, name, reason, admin) VALUES ('" + guid + "', '" + maps\mp\gametypes\_mysql::stripString(self.name) + "', '" + maps\mp\gametypes\_mysql::stripString(reason) + "', '" + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + "')");
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  6. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (22nd June 2016)

  7. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Working with iznogods fix!

  8. #6
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Code:
    	maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO sd_bans_ip (ip, name, reason, admin) VALUES ('" + ip + "', '" + maps\mp\gametypes\_mysql::stripString(self.name) + "', '" + maps\mp\gametypes\_mysql::stripString(reason) + "', '" + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + "')");
    
    	printf("IP ban added to database sd_bans_ip!\n");
    	printf("ip "+ip+ "\n");
    	printf("name "+maps\mp\gametypes\_mysql::stripString(self.name)+ "\n");
    	printf("reason "+maps\mp\gametypes\_mysql::stripString(reason)+ "\n");
    	printf("admin "+maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"])+ "\n");
    It doesnt work with IP?
    Everything is printed correctly.
    IP in mysql is int(11)
    rest are strings

  9. #7
    Private Paho's Avatar
    Join Date
    Feb 2014
    Location
    Russia
    Posts
    101
    Thanks
    43
    Thanked 48 Times in 37 Posts
    I'm use varchar(16)
    Code:
    sql = "INSERT INTO `sd_bans_ip` (`IP`) VALUES ('" + self getIP() + "')";
    mysql_query(level.mysql, sql);
    Last edited by Paho; 16th August 2016 at 16:52.

  10. #8
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by Ni3ls View Post
    It doesnt work with IP?
    Everything is printed correctly.
    IP in mysql is int(11)
    rest are strings
    libcod processes the IP like this:
    PHP Code:
    snprintf(tmp64"%d.%d.%d.%d"ip_aip_bip_cip_d);
    stackPushString(tmp); 
    Last edited by Mitch; 16th August 2016 at 16:58.

  11. #9
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    You should use INET_ATON('" + stripstring(self getip()) + "')"
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  12. #10
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by IzNoGoD View Post
    You should use INET_ATON('" + stripstring(self getip()) + "')"
    And how do I check if an IP is banned?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •