当我使用正确的列名和正确的语句时,为什么我的SQL查询会不断出现错误?
我正在尝试使用MySQL Python和Flask创建书籍数据库系统。我的书籍表中的3列是标题,作者和publish_year。
我有一个sql命令
"SELECT * FROM Books WHERE title=" + str(title)"
,每当我尝试用端点调用我的端点时,
http://127.0.0.1:5000/getbookfromtitle/Twilight
我会发现
Unknown column 'Twilight' in 'where clause'
任何人是否知道会导致此错误的是什么? 我的完整烧瓶功能是
@app.route("/getbookfromtitle/<title>", methods=["GET"])
def getBookFromTitle(title):
if request.method == "GET":
sql = "SELECT * FROM Books WHERE title=" + str(title)
mycursor.execute(sql)
result = mycursor.fetchall()
for x in result:
print(x)
return str(result)
I am trying to create a book Database system using MySQL Python and Flask. My 3 columns in my Books table are title, author, and publish_year.
I have a SQL Command that says
"SELECT * FROM Books WHERE title=" + str(title)"
And whenever I try to call my endpoint with
http://127.0.0.1:5000/getbookfromtitle/Twilight
I get the error
Unknown column 'Twilight' in 'where clause'
Does anyone know what could be causing this error?
My full Flask function is
@app.route("/getbookfromtitle/<title>", methods=["GET"])
def getBookFromTitle(title):
if request.method == "GET":
sql = "SELECT * FROM Books WHERE title=" + str(title)
mycursor.execute(sql)
result = mycursor.fetchall()
for x in result:
print(x)
return str(result)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我想我已经弄清楚了。
在这样做之后,我必须这样做
,它出于某种原因而起作用。
Never mind I think I figured it out.
I have to do
After I did this, it worked for some reason.