Mysql data logging

I have to log 5 data together in different column,
I write this query but it give "ER_PARSE_ERROR" please help.

var co = { payload: msg.payload[0]};

var ox = { payload: msg.payload[1]};

var lux = { payload: msg.payload[3]};

var temp = { payload: msg.payload[2]};

msg.topic = 'INSERT INTOnode-red.final(CO,OX,Lux,Temp) VALUES (' + co + ',' + ox + ',' + lux + ',' + temp + ')';
return msg;

I get data in this form whic i have to log in to my sql.

array[5]
0: "4"
1: "000"
2: "000"
3: "0032"
4: "00"

If you are using node-red-node-mysql, have you looked at the documentation for that node?

If your payload is an array, then the first 4 lines should be

let co = msg.payload[0];

Same for ox, lux and temp

Also are these enter into Db as strings? If so they need to be quoted in the sql statement, or converted to numbers if numeric.

1 Like

Thanks again E1cid.now its working.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.