Reputation: 43
I'm going loopy here and cannot fix my problem. I have looked at many supposed answer that do not fix my error.
I am trying to get temp and humidity data from a DHT11 sensor into a mysql database. I can get the terminal to display the readings and it all works fine except I cannot get the data into the database. There are no problems compiling the c code. It just wont populate the database.
char query[2000];
MYSQL *conn;
conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "drewibbo", "monkeykangaroo", "temp_humidity", 0, NULL, 0);
sprintf(query, "INSERT INTO readings(temp,humidity,date,time) VALUES(%d.%d,%d.%d,2015-02-18,00:00:00)",dht11_val[2],dht11_val[3],dht11_val[0],dht11_$
mysql_query(conn, query);
mysql_close(conn);
Thanks for any help that can be given.
Andy
Upvotes: 2
Views: 3731
Reputation: 12795
Your INSERT query has wrong syntax, you need to put the date and the time into quotes, like.
sprintf(query, "INSERT INTO readings(temp,humidity,date,time) VALUES(%d.%d,%d.%d,'2015-02-18','00:00:00')",dht11_val[2],dht11_val[3],dht11_val[0],dht11_ ...
Your query might have other issues, this is just one that I noticed. Just make your code report errors if they occur: http://dev.mysql.com/doc/refman/5.1/en/mysql-error.html
Upvotes: 1