I am experiencing problems when trying to insert the values of my variables into the database I am trying to do as follows
import MySQLdb
id = 4
idade = 18
nome = 'cebolinha'
email = '[email protected]'
db = MySQLdb.connect("localhost","devel","********","Cadastro")
cursor = db.cursor()
sql = 'INSERT INTO usuarios(id, idade, nome email) VALUES (id, idade, nome, email)'
cursor.execute(sql)
cursor.fetchone()
db.commit()
db.close()
When I go to see the database, it is not inserting the values of my variables and neither does it return any errors.
NowwhenIrunthescriptthiswayit'sworking
importMySQLdbdb=MySQLdb.connect("localhost","devel","********","Cadastro")
cursor = db.cursor()
sql = 'INSERT INTO usuarios(id, idade, nome email) VALUES (3, 17, "daniel", "[email protected]")'
cursor.execute(sql)
cursor.fetchone()
db.commit()
db.close()
remembering that I'm using the python MySQLdb module