0

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)", \
                        username=request.form.get("username"),\
                        hash=pwd_context.encrypt(request.form.get("password"))

    #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"))

else:
    return render_template("register.html")

Here is my error: enter image description here

1 Answer 1

6

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

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

You must log in to answer this question.

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