python + sqlite, insert data from variables into table

前端 未结 3 417
暖寄归人
暖寄归人 2020-12-15 07:36

I can insert hardcoded values into an SQLite table with no problem, but I\'m trying to do something like this:

name = input(\"Name: \")
phone = input(\"Phone         


        
3条回答
  •  -上瘾入骨i
    2020-12-15 08:06

    cur.execute("create table contacts (name, phone, email)")
    
    cur.execute("insert into contacts (name, phone, email) values(?,?,?)",(name, phone, email)) 
    

    OR

    cur.execute("insert into contacts values(?,?,?)",(name, phone, email))
    

    As you are inserting values to all available fields, its okay not to mention columns name in insert query

提交回复
热议问题