Mysql INSERT output in C

I am going to go here and cannot fix my problem. I have looked at many of the alleged answers that do not correct my mistake.

I am trying to get temperature and humidity data from DHT11 sensor in mysql database. I can get the terminal to display the readings and it all works fine except that I cannot get the data in the database. No problem compiling c code. It just doesn't 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 provided.

Andy

+1


source to share


1 answer


Your INSERT query has wrong syntax, you need to put date and time in quotes, for example.

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 request may have other problems, this is just one that I noticed. Just make your own code error messages if they happen: http://dev.mysql.com/doc/refman/5.1/en/mysql-error.html

+1


source







All Articles