0

I can't insert data into sqlite table. Here is my code:

import sqlite3
connection = sqlite3.connect('mydata.db')
cursor = connection.cursor()
a=raw_input('name')
a=str(a)
b=raw_input('theme')
b=str(b)
c=raw_input('language')
c=str(c)
sql="INSERT INTO Website (Website, Theme, Language) VALUES (%, %, %)",(a,b,c)
cursor.execute(sql)
connection.commit()
connection.close()

For some reason it doesn't work.

1 Answer 1

1
  • the extended call syntax is f(*args):

    cursor.execute(*sql)
    
  • sqlite uses '?' placeholder:

    conn.execute('insert into sometable values (?,?,?)', (a,b,c))
    
  • raw_input() already returns a string. a = str(a) is unnecessary
Sign up to request clarification or add additional context in comments.

2 Comments

thanks I tried your code and I get the following error message: Traceback (most recent call last): File "C:\Users\Soso\Desktop\projetpython\database \insert_variables.py", line 13, in <module> cursor.execute(sql) ValueError: operation parameter must be str or unicode
@user1119429: update your question and add full traceback and the code that you've tried.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.