Connection is not defined

when i try the


connection.on('error', function(err) {
  console.log(err.code);
});
``` code i get  "Connection is not defined"

Hey @DentyModsReal, welcome to the Glitch forum!

That error message probably indicates an issue elsewhere in your code. I think we’ll need to see more of the code before anyone can help (or better yet the name of your project so we can look at all of the code).

ok and my code is not on glitch, i just found this support page



const mySQL = require("mysql");
const con = mySQL.createConnection({
    host: "remotemysql.com",
    port: "3306",
    user: "no",
    password: "ha no",
    database: "no"
});




    con.connect(err => {
    if(err) throw err;
    console.log("Connected To Database!")
    

    con.on('error', function(err) {
        console.log(err.code);
      });


    con.query("SELECT COUNT(*) FROM xp", function (err, result) {
        if (err) throw err;
        console.log(`--------------------------------------------`)
        console.log('Total Users In Database (lmao still working on it)')
        console.log(result); 
    });
    });

function generateXp(){
      return Math.floor(Math.random() * (30 - 10 + 1)) + 10;
}






    
  con.query(`SELECT * FROM xp WHERE id = '${message.author.id}'`, (err, rows) => {        if(err) throw err;
                let sql;
            
               if(rows.length < 1) {
                  sql = `INSERT INTO xp (id, xp) VALUES ('${message.author.id}', ${generateXp()})`;
        
            } else {
                let xp = rows[0].xp;
                sql = `UPDATE xp SET xp = ${xp + generateXp()} WHERE id = '${message.author.id}'`;
            }
            con.query(sql, console.log);
        
        
           });

might be a error in there because i have other codes that are not sql that i removed from that

From that it looks as though you had a variable name incorrect (you had connection but the variable was con), and it looks like you’ve fixed it there, so maybe you’re seeing a different error now?

And for what it’s worth, although folks around here are friendly and helpful and may be able to help you find a solution, we’re mostly here to help folks who are using Glitch. You might have better (and faster) luck somewhere like stackoverflow.com for this sort of general coding question.

oh sorry i tried connection and it didint work so i was going to see if con worked
and ok thx