0

I'm receiving this error of undefined data.

throw err; // Rethrow non-MySQL errors

TypeError: Cannot read property 'updates_title' of undefined

My node.js code which is causing an issue:

app.get("/aktualnosci/:update_id", function(req, res){
   console.log(req.params.update_id);
   con.query("SELECT * FROM tbl_updates WHERE updates_id = ('"+req.params.update_id+"')" , function(err, result, fields){
     console.log(result[0]);
     res.render('aktualnosci', {title: result[0].updates_title, text: result[0].updates_title});
   });   
});

Jade code:

.container
   hr
   .row
      .col-lg-6
         h1 #{title}
   .row
      .col-lg-12
         p #{text}

Also i got console log of data i'm receiving from database

RowDataPacket {
updates_id: 4,
updates_title: 'Czwarty post, !!!',
updates_text:'LOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLOREMLORLOREMLOREMLOREMLOREMLOREM' }

The problem is why the error is occurring when it's clearly shown that data is not undefined.

Kynio
  • 1
  • 2
  • 1
    I don't see a problem with MySQL, please remove the tag. Quick read of the problem suggests that the object you're trying to read from (`result[0].updates_title`) tries to read `updates_title` from undefined object. Meaning that your `result[0]` is `null`. Have you checked `console.log(result)`? If `result` is an object (so not an array!), have a look [at this question](https://stackoverflow.com/questions/983267/access-the-first-property-of-an-object) about accessing the `n-th` property of an object instead of by name (such as `result.firstResult`). – rkeet Sep 12 '17 at 12:33
  • I see a huge SQL injection vector in the MySQL part... – robertklep Sep 12 '17 at 13:36

0 Answers0