flask sql cann't insert Variable in VALUES

Chris Angelico rosuav at gmail.com
Fri Jul 4 06:24:26 EDT 2014


On Fri, Jul 4, 2014 at 8:15 PM, Frank Liou <fk26541598fk at gmail.com> wrote:
> I try to insert username in to my table
>
> it show
>
> Internal Server Error
> The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
>
> ...
> def save_friends(username):
>     conn = engine.connect()
>     conn.execute("INSERT INTO friends(name) VALUES(username)")

There are two things that you need to understand here, and rather than
give you the answers, I'm going to point you toward what you should
know. The first one is that your result page simply tells you that
there was an error; you need to look in the server logs to find the
actual text of the error. Get to know those logs; they'll collect all
sorts of errors for you. And the second is about the nature of SQL and
Python. Have a look at the basic documentation on parameterized
queries, and *be sure you understand it*. There is a lot more at stake
here than you might realize, so I'm not simply going to explain what's
wrong here; you absolutely must comprehend parameterized queries.

ChrisA



More information about the Python-list mailing list