0

I have a POST request like this:

var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.post('/readings', urlencodedParser,function(req, res){
  console.log(req.body);
  var Sensor = req.body;
  res.render('readingsChart');
});

and I want to use "Sensor" outside the app.post(), In an another GET request for example like this:

var queryString = 'SELECT Time, Reading FROM myTable WHERE Sensor = '+Sensor;

app.get('/getSQL', function(req, res) {
 connection.query(queryString, function(error, rows, fields) {
   if(error){console.log(error);}
   else{console.log('Connected');}
   // My Code
 });
});

I keep having this error:

var queryString = 'SELECT Time, Reading FROM '+table+' WHERE Sensor = '+Sensor;
                                                                        ^

ReferenceError: Sensor is not defined
einpoklum
  • 118,144
  • 57
  • 340
  • 684
A.Kallas
  • 75
  • 1
  • 10

0 Answers0