Hello all,
My am trying to insert a record with a string and a floating parameter, but fail. Please, have a look at my code and give me some advice.
import MySQLdb
Vstring = 'string' Vfloat = 1.1
conn = MySQLdb.connect (host = "localhost", user = "root", passwd = "root", db = "test")
cursor = conn.cursor () cursor.execute ("""INSERT INTO table1(text, num) VALUES (%s,%f)""", (Vstring,Vfloat)) cursor.execute ("SELECT text, num FROM table1")
conn.commit()
cursor.close () conn.close ()
Thanks in advance.
Thank Andy,
It works perfectly.
Do this instead:
cursor.execute ("""INSERT INTO table1(text, num) VALUES (%s,%s)""", (Vstring,Vfloat))
Next time, post the error traceback.
Log in to post a comment.
Hello all,
My am trying to insert a record with a string and a floating parameter, but fail. Please, have a look at my code and give me some advice.
import MySQLdb
Vstring = 'string'
Vfloat = 1.1
conn = MySQLdb.connect (host = "localhost", user = "root", passwd = "root", db = "test")
cursor = conn.cursor ()
cursor.execute ("""INSERT INTO table1(text, num) VALUES (%s,%f)""", (Vstring,Vfloat))
cursor.execute ("SELECT text, num FROM table1")
conn.commit()
cursor.close ()
conn.close ()
Thanks in advance.
Thank Andy,
It works perfectly.
Do this instead:
cursor.execute ("""INSERT INTO table1(text, num) VALUES (%s,%s)""", (Vstring,Vfloat))
Next time, post the error traceback.