title: Display data after user input form (mysql-nodejs)
body: <p>I have a page where there is a form, in which user will fill inputs. Then, I redirect to another page in which depending on the user's choices some data will be displayed (the data will come from a mysql database). This is my code: <br>
  <strong>index.js</strong> (here are my routes)</p>
  <pre><code>var express = require('express');
  var router = express.Router();
  
  // Controllers
  const airTicketsController = require('../controllers/airTicketsController');
  
  /* GET home page. */
  router.get('/', function(req, res, next) {
      res.render('home', { title: 'Express' });
  });
  
  // Air tickets page
  router.get('/air_tickets', function(req, res, next) {
      res.render('air_tickets', { title: 'Air tickets' });
  });
  
  router.post('/form-submit', airTicketsController.airForm);
  router.get('/air_ticketsSelect', airTicketsController.displayFlights);
  
  module.exports = router;
  </code></pre>
  <p><br><strong>airTicketsController.js</strong> (a controller where mysql queries will be executed)</p>
  <pre><code>const mysql = require('mysql');
  
  // DB connection
  const connection = mysql.createConnection({
      host: 'localhost',
      user: 'myuser',
      password: 'mypassword',
      database: 'mydatabase'
  });
  
  connection.connect(function(error) {
      if (!!error) console.log(error);
      else console.log('CONGRATS! Database Connected! (airTicketsController)');
  });
  
  var variable1, variable2;
  
  exports.airForm= (req, res) =&gt; {
      variable1 = req.body.from_destination;
      variable2 = req.body.to_destination
      res.redirect('/air_ticketsSelect');
  }
  
  exports.displayFlights= (req, res) =&gt; {
      variable1 = req.body.from_destination;
      variable2 = req.body.to_destination
      connection.query(&quot;SELECT * FROM flight WHERE from_destination=? AND to_destination=?&quot;, [variable1, variable2], function(err, results, fields) {
          if (err) throw err;
          res.render('air_ticketsSelect', {
              title: 'flightdata',
              data: results
          });
      });
  }
  </code></pre>
  <p><br><strong>air_tickets.ejs</strong> (the page for the form)</p>
  <pre><code>&lt;form id=&quot;form-submit&quot; method=&quot;post&quot; action=&quot;form-submit&quot;&gt;
                              &lt;div class=&quot;container&quot; id=&quot;air-form-container&quot;&gt;
                                  &lt;div class=&quot;row&quot;&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;div class=&quot;form-group&quot;&gt;
                                              &lt;label for=&quot;from_destination&quot;&gt;From: &lt;/label&gt;
                                              &lt;br&gt;
                                              &lt;input type=&quot;text&quot; name=&quot;from_destination&quot; class=&quot;form-control&quot; placeholder=&quot;City or airport&quot;&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;div class=&quot;form-group&quot;&gt;
                                              &lt;label for=&quot;to_destination&quot;&gt;To: &lt;/label&gt;
                                              &lt;br&gt;
                                              &lt;input type=&quot;text&quot; name=&quot;to_destination&quot; class=&quot;form-control&quot; placeholder=&quot;City or airport&quot;&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;br&gt;
                                  &lt;div class=&quot;row&quot;&gt;
                                      &lt;div class=&quot;col-md-12&quot;&gt;
                                          &lt;div class=&quot;form-btn&quot;&gt;
                                              &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; id=&quot;submit-btn&quot;&gt;Search flights 
                                              &lt;i class=&quot;fas fa-search&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;
                                          &lt;/button&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
  </code></pre>
  <p><br><strong>air_ticketsSelect.ejs</strong> (the page for displaying the data)</p>
  <pre><code>&lt;table class=&quot;table table-dark table-striped&quot;&gt;
                          &lt;thead&gt;
                              &lt;tr&gt;
                                  &lt;th&gt;Id&lt;/th&gt;
                                  &lt;th&gt;Airline&lt;/th&gt;
                                  &lt;th&gt;From&lt;/th&gt;
                                  &lt;th&gt;To&lt;/th&gt;
                                  &lt;th&gt;Depart date&lt;/th&gt;
                                  &lt;th&gt;Arrival date&lt;/th&gt;
                                  &lt;th&gt;Depart time&lt;/th&gt;
                                  &lt;th&gt;Arrival time&lt;/th&gt;
                                  &lt;th&gt;Price&lt;/th&gt;
  
                              &lt;/tr&gt;
                          &lt;/thead&gt;
                          &lt;tbody&gt;
                              &lt;% data.forEach(function(flight){ %&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.flight_id %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.airline %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.from_destination %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.to_destination %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.depart_date.toLocaleDateString('el-GR') %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.arrival_date.toLocaleDateString('el-GR') %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.depart_time %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.arrival_time %&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;%= flight.flight_price + ' €' %&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;% }); %&gt;
                          &lt;/tbody&gt;
                      &lt;/table&gt;
  </code></pre>
  <p><br> In general, I think this is supposed to work. However, it doesn't display the data, only an empty table. If I do the query manually (e.g. SELECT * FROM flight WHERE from_destination = 'Paris' AND to_destination = 'London'), it will work correctly..
  <br> When I console.log the query it says that: <br>
  sql: 'SELECT * FROM flight WHERE from_destination=NULL AND to_destination=NULL',
  values: [ undefined, undefined ]</p>