0

What mistake am I doing in the code below for pset9 "register" function:

@app.route("/register", methods=["GET", "POST"])
def register():
    """Register user"""

    if request.method == "GET":
        return render_template("register.html")

    elif request.method == "POST":

        # Ensure username was submitted
        if not request.form.get("username"):
            return apology("must provide username", 400)

        # Ensure password was submitted
        elif not request.form.get("password"):
            return apology("must provide password", 400)

        # Ensure password confirmation was submitted
        elif not request.form.get("password-confirmation"):
            return apology("must provide password confirmation", 400)

        # Check if the password confirmation field matches the password field
        elif request.form.get("password-confirmation") != request.form.get("password"):
            return apology("Your passwords didn't match", 400)


        # Insert username and password into the database AND Hash user's password
        insert = db.execute("INSERT INTO users (username,hash) VALUES(?,?)" , request.form.get("username"), generate_password_hash(request.form.get("password"))

        # Query database for that username
        row = db.execute("SELECT * FROM users WHERE username = ?", request.form.get("username"))

        # Database
        database = db.exexcute("SELECT * FROM users")

        # Ensure username is not already in the database
        if row in database:
            return apology("username already exists", 400)

        # Remember which user has logged in
        session["user_id"] = insert

        # Redirect user to home page
        return redirect("/")

Its giving me the below error:

row = db.execute("SELECT * FROM users WHERE username = ?", request.form.get("username")) ^ SyntaxError: invalid syntax

You must log in to answer this question.

Browse other questions tagged .