python + sqlite, insert data from variables into table

前端 未结 3 433
暖寄归人
暖寄归人 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条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 08:17

    You can use ? to represent a parameter in an SQL query:

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

提交回复
热议问题