I am just starting pset7 and I thought I had fully completed register, but I keep getting an invalid syntax error on this line:

if not result:

I am really confused as this is a really simple line and copied directly from the walkthrough. I have tried everything and cannot figure out this error! Thanks for all the help in advance!

Here is my code for register:

@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user."""
# get username/password
#<input name= "name", password= "password", password_confirmation= "password_confirmation"
if request.method == "POST":
    #if field is blank
        # print apology
    if not request.form.get("username"):
        return apology("you must provide a username :(")
    elif not request.form.get("password"):
        return apology("you must provide a password :(")

    #check if passwords match
    elif request.form.get("passwordconfirmation") != request.form.get("password"):
        return apology("you must provide a password confirmation the same as your password!!!")

    #store values in database
    result = db.execute("INSERT INTO users (username, hash) \
                        VALUES(:username, :hash)", \

    #db.execute failure
    if not result:
        return apology("please pick a new username")

    #log user in
    session["user_id"] = result

    return redirect(url_for("index"))

    return render_template("register.html")

Here is my error: enter image description here


When an obviously correct line gives a syntax error, look to the preceding line. Are there enough ')' on the db.execute?

  • Thanks for this answer, applied to a similar problem I had.. Jul 22 '17 at 6:34
  • Thank you so much! Jul 22 '17 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .