I am trying to pass a key value and generate a JSON response based on the key passed
Express Program
var express =
You have two handlers for the path /RestaurantDesc/
- only one should be kept.
In your query, the syntax is wrong.
Assuming you have a table that looks like this (change these names to match your schema):
Table Name: Restaurant
column: name
And you are using node-mysql, Change your query to something like this:
connection.query('SELECT * FROM Restaurant where name = ?', [keyName], function (err, rows, fields) {
console.log('Connection result error ' + err);
name_of_restaurants = rows;
callback();
});
The ? is a place holder for values passed in the array of values passed in the second parameter to query
.
See: Escaping query values for more information on how this works. Short answer though is that the values will be escaped properly using this approach.