Express to generate JSON

前端 未结 3 1271
滥情空心
滥情空心 2021-01-17 00:46

I am trying to pass a key value and generate a JSON response based on the key passed

Express Program

var express =         


        
3条回答
  •  Happy的楠姐
    2021-01-17 01:40

    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.

提交回复
热议问题