-1

so my problem is that I'm getting one very annoying error when I try to remove a warning and update it in my database. I do not know what is wrong but if I wrote everything correctly then it should normally work but it gives an error... I want it when I type to remove a warning it removes 1 from the users database and then it sets the warning ID to 0 (warns and warn ID's are stored separately) the warn ID's work perfectly but removing the warn count (wn = warn number, wid = warn id) is a problem. I need to remove 1 from it but it throws the following error:

(---- = Censored because there was my name)

Error: 

    throw er; // Unhandled 'error' event
      ^

Error: Unknown column 'NaN' in 'field list'
    at Packet.asError (C:\Users\------\Desktop\Te\node_modules\mysql2\lib\packets\packet.js:712:17)
    at Query.execute (C:\Users\------\Desktop\Te\node_modules\mysql2\lib\commands\command.js:28:26)
    at Connection.handlePacket (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:417:32)
    at PacketParser.onPacket (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:75:12)
    at PacketParser.executeStart (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\packet_parser.js:75:16)
    at Socket.<anonymous> (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:82:25)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
Emitted 'error' event on Query instance at:
    at Query.execute (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\commands\command.js:33:14)
    at Connection.handlePacket (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:417:32)
    [... lines matching original stack trace ...]
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  code: 'ER_BAD_FIELD_ERROR',
  errno: 1054,
  sqlState: '42S22',
  sqlMessage: "Unknown column 'NaN' in 'field list'"
}

And this is my code for it: (It may be long but it is for removing a warning.)

if(args[1] === "remove" && message.member.roles.cache.has(rls.Adminid) || message.member.roles.cache.has(rls.SAdminid) || message.member.roles.cache.has(rls.HAid) || message.member.roles.cache.has(rls.CAdminid) || message.member.roles.cache.has(rls.oid)){
  if(!message.mentions.users.first()){
    message.reply("Mention a user to remove a warning from.");
    return;
  }
  var u = message.mentions.users.first();
                    
  if(rows[0].wid === args[3]){
  if(!args[2]){
    message.reply("Please may you add a warning ID to it?")
    return;
  }
   let waid = parseInt(args[2]);
  con.query(`SELECT * FROM warns WHERE id = ${u.id} AND wid = ${waid}`, (err, rows) => {
    if (err) throw err;
    let sql;
    if(rows.length < 0){
      sql = `INSERT INTO wrni (id, wn) VALUES (${u.id}, '0')`;
      con.query(sql);   
     }
    sql = `UPDATE wrni SET wn = ${rows[0].wn - 1} WHERE id = ${u.id}`;
    con.query(sql);
    sql = `UPDATE warns SET wid = 0 WHERE wid = ${args[2]}`;
    con.query(sql);
    let emb = new MessageEmbed()
    .setAuthor("Warning has been removed!", u.displayAvatarURL())
    .addField("From user:", u.tag, true)
    .addField("User's ID:", u.id, true)
    .addField("Moderator:", message.author.tag)
    .addField("Warn ID:", waid)
    .setColor("GREEN");
    let c = message.guild.channels.cache.find(c => c.id === "706906999828250734")
    c.send(emb);
    message.channel.send("Warning removed from " + u.tag + "! User now has: " + rows[0].wn + " warnings!");
    return;
  })

Database:

SELECT * FROM wrni;
+--------------------+----+
| id                 | wn |
+--------------------+----+
| 342364288310312970 |  2 |
| 317644533208711169 |  0 |
+--------------------+----+


SELECT * FROM warns;
+--------------------+--------+
| id                 | wid    |
+--------------------+--------+
| 1000               | 0      |
| 342364288310312970 | 0      |
| 317644533208711169 | 0      |
| 342364288310312970 | 0      |
| 342364288310312970 | 0      |
| 342364288310312970 | 0      |
| 342364288310312970 | 0      |
| 342364288310312970 | 991839 |
| 342364288310312970 | 0      |
| 342364288310312970 | 411735 |
+--------------------+--------+

0 = Warn removed
Random numbers = Warn remaining.

So yea I don't know what is wrong with my code but it just isnt working. I tried to fix it many different ways but none of them worked.

Zer0
  • 1,580
  • 10
  • 28

1 Answers1

0

Oh it just fixed it self idk how but it did and it works now. I havent edited any of the code. So I can't post the solution here..