Saving Data in DB at SQLite Function - Help!

Yes I tried but didnt work unfortunately.

After I tried I asked you, what I making wrong I dont know.

But you didn't say you had tried it and you didn't provide any information about what happened. I'm sorry, but you have to help us to help you.

You can see the error coming back from the SQLITE node when you pass it those queries.

no such table: Status

I hope you can guess what that means.... it's hard to be much clearer. You need to create the database table in sqlite before you can insert data into it.

Sorry.

Eventually I did it with replacing code. I used this code for values sending db.

var date = Date.now();
var newMsg = {
    "topic": "INSERT INTO Status VALUES ( " + date + ", " +
    msg.payload + ", " + msg.humidity + ")"
}
return newMsg;

I almost completed my project first part saving data.
But in phpmyadmin some records saving many times in like picture. Any solution you advice me ?

Also Device name should be static, like Laser 1 - Laser 2 .... like this. How can I make this ?

You see how you split the flow at the begining to go to the teo function nodes? Now you have two msg's going to the next flow and it creates two outputs for every input

so 1 reading from the dht11 becomes two msgs that become 4 sql statements. You sure that is what you want to do?

Dear @zenofmud my english is not enough good. Just want try to what this sentence mean.

I just want to 1 record, one of them temperature other one is humidity. Just make this.

since the original msg has both the temperature (msg.payload) and the humidity (msg.humidity) you can get rid of the 'temperature' node since it really doesn't do anything. Next remove the line from the humidity function node to the Insert Statement node. and you should be all set.

Ok I will try and share results, thanks.
But I used 2 function node one of them temp and the other humid graph and gauge. Is one function enough for showing both ?

The only reason you NEED the humidity function is to move the msg.humidity to msg.payload (you could have used a change node) so you can pass the data to the graph in msg.payload

Other problem is solved and now started new one, I want to send dsm status to DB but after deployment I take an "SyntaxError: Unexpected token )"

Not saving values and date and other to db, any advice ?

Please export your flow and paste it into a reply and make sure to add the back tic’s

Here is my flow.

[{"id":"48b91207.ef6bec","type":"rpi-gpio in","z":"3acbc945.b2c336","name":"","pin":"40","intype":"tri","debounce":"25","read":false,"x":410,"y":220,"wires":[["544b54b5.c1860c"]]},{"id":"544b54b5.c1860c","type":"dsm","z":"3acbc945.b2c336","name":"state right","sm_config":"{\n    \"triggerInput\": \"payload\",\n    \"currentState\": \"running\",\n    \"states\": {\n        \"stopped\": {\n            \"0\": \"running\"\n        },\n        \"running\": {\n            \"1\": \"stopped\"\n        }\n    },\n    \"methods\": {\n        \"onBeforeTransition\": \"msg.pyload = msg.payload.toString();\",\n        \"0\": \"sta.fill='green';msg.background='green';msg.label='Laser 1 Working';\",\n        \"1\": \"sta.fill='red';msg.background='red';msg.label='Laser 1 Error!!!';\"\n    }\n}","x":596,"y":218,"wires":[["361c506e.fba1b","5c067af9.126b44","c68ffb5b.cde4e8"]]},{"id":"361c506e.fba1b","type":"ui_button","z":"3acbc945.b2c336","name":"Laser 1","group":"5e2b93d7.7465fc","order":0,"width":0,"height":0,"passthru":false,"label":"{{msg.label}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"str","topic":"","x":760,"y":140,"wires":[[]]},{"id":"5c067af9.126b44","type":"debug","z":"3acbc945.b2c336","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750,"y":180,"wires":[]},{"id":"c68ffb5b.cde4e8","type":"function","z":"3acbc945.b2c336","name":"insert Statement","func":"var date = Date.now();\nvar topic = ();\nvar label = ();\n\nvar newMsg = {\n    \"topic\": \"INSERT INTO cube VALUES ( \"+ date +\" , \" +\n    msg.topic + \",\" + msg.label + \",\" + msg.payload + \")\"\n}\n\nreturn newMsg;","outputs":1,"noerr":0,"x":800,"y":220,"wires":[["9e9baecc.2325f"]]},{"id":"9e9baecc.2325f","type":"sqlite","z":"3acbc945.b2c336","mydb":"44d3ca4a.01a264","sqlquery":"msg.topic","sql":"","name":"Record","x":960,"y":220,"wires":[[]]},{"id":"ef8b2b30.2a6698","type":"inject","z":"3acbc945.b2c336","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":180,"wires":[["544b54b5.c1860c"]]},{"id":"5e2b93d7.7465fc","type":"ui_group","z":"","name":"Assembly Lines","tab":"3e7f6350.5b23cc","disp":true,"width":"6","collapse":false},{"id":"44d3ca4a.01a264","type":"sqlitedb","z":"","db":"/var/www/html/database/cube","mode":"RWC"},{"id":"3e7f6350.5b23cc","type":"ui_tab","z":"","name":"Chasis Lines","icon":"dashboard"}]

add a debug node to the output of your 'Insert Statement' function node and set it to display complete message and what does it show?

also in your DSM node you have
"onBeforeTransition": "msg.pyload = msg.payload.toString();",
Do you really want to create msg.pyload?

you can see in picture..
It looks good but, also want to see +stopped and running text not ( 1 or 0 ) + date and time in Db , how can I add this ?

@wtrk modify your query so you're inserting the information you want. Your query currently inserts msg.payload in the query. If you want the text, then appears to be in msg.topic instead.

You have changed the function node. Why? All I asked you to do was to add the debug node in.

If you are going to change things between your posts, it makes it hard to help you.

I dont know what this code is doing and if not necessary, I dont want it

Just deleted
var topic = ();
var label = ();

Because, when I deploy the flow it starts with error, you can see in picture.

ok, this is the key - you show two insert statements that are different but one works and the other doesn't. The two columns you are adding are defined as text in the DB so they need to have quote marks around them in the final sql statement.

ThIs can be tricky because you have to escape the quotes to use them inside quote. thy this in your function

var newMsg = {
    "topic": "INSERT INTO cube VALUES ( "+ date +" , \"" +
    msg.topic + "\",\""  + 
    msg.label + "\"," + msg.payload + ")"
}

I wrote not needed message, sorry