0

This is my first time trying to store information to MySQL database. I made a server file with all the necessary dependencies implemented, as well as a database on port:8080 (localhost). When trying to send the information from server to database its not sending anything (I think because nothing shows up in database), but the web shows the res.send() message I insert.

My code:

const db = mysql.createConnection({
    user:"root",
    port:"8080",
    host: "localhost",
    password: "password",
    database: "baza",
})

app.get("/", (req,res)=>{
    const InsertSql= "INSERT INTO user_reg (`username`,`email`,`password`) VALUES ('vedo','lol','hi');"
    db.query(InsertSql,(err,result)=>{
        res.send("hi");
    });//TODO

});

The word hi displays on port localhost/3001 but the information I want to send to DB using const InsertSql= "INSERT INTO user_reg (username,email,password) VALUES ('vedo','lol','hi');" does not.

If anyone knows how to resolve this issue it would be great, thanks in advance

David
  • 208,112
  • 36
  • 198
  • 279
Vedo
  • 976
  • 4
  • 21
  • Is there anything in `err` in the query callback? – David Jun 15 '21 at 11:06
  • How do I check that, if you mean in terminal it displays that everything is working fine – Vedo Jun 15 '21 at 11:07
  • You could log `err` to the console or some kind of logging output, keeping in mind that the *server* console is not the same thing as the *browser* console. Or perhaps return `err` to the client to observe it in the browser's debugging tools (in the network response). Basically you need to debug and observe what's happening, because MySQL could very well be telling you something is wrong and you're currently just not looking. – David Jun 15 '21 at 11:09
  • {"code":"ER_ACCESS_DENIED_ERROR","errno":1045,"sqlMessage":"Access denied for user 'root'@'localhost' (using password: YES)","sqlState":"28000","fatal":true} this is the error message it displays when I run the err – Vedo Jun 15 '21 at 11:12

0 Answers0