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)