0

Hello I am working in Express Framework, I am using handlebars to render the data from my mysql table. While trying to render the data using below code,instead of rendering value it displaying [object object]. I posted my code below.

index.js:

 var query = connection.query('SELECT * FROM requestor_auth WHERE question_id = ? AND answer = ? AND app_key = ?  LIMIT 1', [data.qid, data.ansvalue, data.appid], function(err,rows)
    {

        if(err) {
            console.log("Error Selecting : %s ",err );
            res.redirect('/');
        } else {
            res.render('requestform',{page_title:"Edit Customers - Node.js",data:rows});
          }

requestform.hbs:

    <div class="addressto">
              <h4>To,</h4>
                <br>
                  <span style="font-size:18px;margin-left:10px;">The Collector Of</span>
                  <input type="text" value="{{data}}" class="line" class="text-line" style="margin-left:35px;"><br>

    </div>

The value in the form input displaying as [object object]. I tried as data.key_value to render the data but it is not displaying the value. Please give me a solution. Thank you.

2 Answers 2

1

Because the result of Mysql response is array so it should be:

 var query = connection.query('SELECT * FROM requestor_auth WHERE question_id = ? AND answer = ? AND app_key = ?  LIMIT 1', [data.qid, data.ansvalue, data.appid], function(err,rows) {

        if(err) {
            console.log("Error Selecting : %s ",err );
            res.redirect('/');
        } else {
            res.render('requestform',{page_title:"Edit Customers - Node.js",data:rows[0]});
          }

If there's a same error you should console.log() your result to check the value.

Sign up to request clarification or add additional context in comments.

1 Comment

Great, @ Burdy data is displaying in the form. Thank you
0

The rows argument in your callback function is by a select query always an array of objects. With handlebars you should be able to do the following:

<div class="addressto">
    <h4>To,</h4>
    <br>
    <span style="font-size:18px;margin-left:10px;">The Collector Of</span>
    <input type="text" value="{{data[0].answer}}" class="line text-line" style="margin-left:35px;">
    <br>
</div>

Also multiple class names can be in one class attribute.

1 Comment

Hi Dirk, I have tried your code, but it is throwing parse error.Expecting ID, STRING, BOOLEAN, etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.