I am trying to query my AWS RDS database by getting a value I submit in an html form to pass to the backend and use it in a SQL statement. This is my form:
Show all
<form method="GET" action="/all">
<select name="all">
<option value="crimes">Crimes</option>
<option value="schools">Schools</option>
<option value="walkscore">Walkscore</option>
</select>
data
<input type="submit" value="GO!">
</form>
This is my JS code:
app.get('/all',function(req,res){
var table = req.query['all'];
connection.query('SELECT * from ' + table, function(err, rows, fields) {
if(err) {
console.log(err);
res.send(500);
}
console.log('The solution is: ', rows);
connection.end();
res.send(rows);
});
});
When I do this, it prints in my console after a long time with a list of RowDataPackets, but then it errors out with
Cannot enqueue Query after invoking quit
and
Cannot enqueue Quit after invoking quit.
Clearly it is connecting to the db because I am getting rows. However, it hangs in my browser and gives an internal server error.
How do I fix this to send the response data to the same html page I have my form on for front end parsing?