You cant check the result from the database before getting the result from the database.
You don't want to set usernamedata to None either that was just an example.
put it in the start of your main if statement
You don't want to set usernamedata to None either that was just an example.
put it in the start of your main if statement
@app.route("/login", methods=["GET","POST"]) def login(): password = request.form.get("password") username = request.form.get("username") usernamedata = db.execute("SELECT username FROM users WHERE username=:username", {"username":username}).fetchone() passworddata = db.execute("SELECT password FROM users WHERE username=:username", {"username":username}).fetchone() if not usernamedata: print('invalid username') eiif username is not None and usernamedata[0] == username and passworddata[0] == password: print("welcome") return render_template("welcome.html") elif username is not None and (usernamedata[0] != username or passworddata[0] != password): print("no match") return render_template("login.html") else: print("empty") return render_template("login.html")