Hello, I’m a beginner with SQL and Flask and i’m having issues with a part of my website.
My goal is that a user fills an HTML form in which they fill in a value (in my case it's "name").
And with that information, the program has to check if this "name" is in the database:
* if it's in the database, you go to a webpage that prints out the other information associated with "name
(for example it prints out : "name","email","address")
* if it's not it sends you to a webpage that tells the user that the "name" doesn't exist in the database. (or "error" in my case)
My issue is that in this part of the code, it always sends the webpage where it indicates an "error"(line 13) even though I've inputed the correct information for it to normally work.
And when I remove the "except" command, I get this message after filling in the form:
UnboundLocalError: local variable 'tuple' referenced before assignment
* Here is an exctract of the python code:
My goal is that a user fills an HTML form in which they fill in a value (in my case it's "name").
And with that information, the program has to check if this "name" is in the database:
* if it's in the database, you go to a webpage that prints out the other information associated with "name
(for example it prints out : "name","email","address")
* if it's not it sends you to a webpage that tells the user that the "name" doesn't exist in the database. (or "error" in my case)
My issue is that in this part of the code, it always sends the webpage where it indicates an "error"(line 13) even though I've inputed the correct information for it to normally work.
And when I remove the "except" command, I get this message after filling in the form:
UnboundLocalError: local variable 'tuple' referenced before assignment
* Here is an exctract of the python code:
@app.route("/searchrecord",methods = ["GET","POST"]) def searchrecord(): name = request.form["name"] with sqlite3.connect("Student.db") as con: try: cur = con.cursor() cur.execute("SELECT name, email, address FROM Student") records = cursor.fetchall() for i in records: if i[0] == name: tuple = i except: tuple = 'Error' finally: return render_template("search_record.html",tuple = tuple)* And the HTML code for "searchrecord":
<!DOCTYPE html> <html> <head> <title>search record</title> </head> <body> <h3>{{tuple}}</h3> <a href="/view">View List</a> </body> </html>So I'd like try to try to fix the issue where it seems that it's unable to extract and print out the result of the "try" (line 5) block.
Attached Files