I want to insert the value of variable (temp, hum) into my table sensors using mysql database (db name:project). I am using Ubuntu 14.04, and the connection is made between python and MySQL, but I can't put the value of the variable. So any help is welcome, and thanks.
This is my script Python:
from random import *
import socket
import sys
import mysql.connector
from datetime import datetime
temp = randrange(10, 31, 2)
hum = randrange(300, 701, 2)
print temp
print hum
conn=mysql.connector.connect(user='root',password='12345',host='localhost',database='projet');
mycursor=conn.cursor();
mycursor.execute("""INSERT INTO sensors VALUES('$datetime','$temp','$hum')""");
conn.commit()
mycursor.execute("SELECT * FROM sensors")
This is my table where you can find the variables temp and hum and not their values: