Welcome to the Treehouse Community
Looking to learn something new?
Inserting into database, incorrect number of bindings supplied (Flask, SQL, Python)
I am trying to make a simple messageboard/twitter type website. It contains a text entry input and a post button. You type something in, hit post, and the page refreshes with your post added to the top.
I have this setup in Flask framework and am having trouble posting the entries into the database. (I can read them just fine if I insert using sqlite browser). The database is a table called entries and each entry has a row that contains an autoincrement ID and the text from the entry field.
The problem I am having is that when I try to insert into the database via POST it sees the characters of the text entered as individual entries. For example if I enter 12345 it will try to post 1,2,3,4,5 separately. See the pictures for a better explanation
Entering text http://drp.io/obD
Traceback, incorrect number of bindings http://drp.io/obC
If I enter just 1 character, it works perfectly. I'm fairly certain it has something to do with the way I am adding to the database. Here is my query (couldn't get it to format)
g.db.execute('INSERT INTO entries (text) VALUES (?)', request.form['posts'])
(posts is the name of the textarea)
Hopefully I just missing a comma or something. I can provide more code if needed.
Thanks in advance for any replies!
Could you share some more of the code around the SQL?