1

Whenever i try to run the following code i get an error saying that theres no such column "title_data", im really confused because "TITLE" is the column not "title_data"

def insertData(self):
    title_Data = self.edit_title.text()
    year_Data = self.edit_year.text()
    rating_Data = self.edit_rating.text()


    connection = sqlite3.connect('films.db')
    try:
        connection.execute("INSERT INTO FILMS (TITLE,YEAR,RATING) VALUES(title_Data,year_Data,rating_Data)")


    except sqlite3.IntegrityError:
        print("You have already stored this data")
    connection.commit()
    connection.close()

1 Answer 1

2

You're not passing your variables correctly. Instead of

connection.execute("INSERT INTO FILMS (TITLE,YEAR,RATING) VALUES(title_Data,year_Data,rating_Data)")

You should use

connection.execute("INSERT INTO FILMS (TITLE,YEAR,RATING) VALUES(?,?,?)", (title_Data,year_Data,rating_Data))

See the docs for execute() for more information.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much , im relatively new to sqlite3 thank you.
@Noob that's ok! If this helped you, you can mark it as the answer and/or vote it up using the buttons on the left of it.
Could you help me out with one more thing?
@Noob Is it related? If so, yes. If not, you might need to open another question.
its part of the same program but not this question. Ill open another question.

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.