0

if request.method == "POST":

    if not (request.form.get("password") or request.form.get("confirmation") or request.form.get("username")):
        return apology("please enter all details", 403)



    if request.form.get("confirmation") != request.form.get("password"):
        return apology("entered passwords don't match", 403)

    hash1 = generate_password_hash(request.form.get("password"))
    result=db.execute("INSERT INTO users(username, hash) VALUES(:username, :password)",\
    username=request.form.get("username"),\
    password= hash1)

    if not result :
        return apology("username already taken", 403)


    #Remember which user has logged in
    session["user_id"] = result[0]["id"]

    return redirect("/")
else:
    return render_template("register.html")
2

Two problems with this bit values(username:, password:".

  1. missing close paren
  2. the : goes in front of the bind variable.

( keywords in sqlite are case insensitive)

0
1

On a quick glace maybe:

On the result line: VALUES in capitals and (:username, :password")

4
  • Also, should examine the return value of INSERT as per docs.cs50.net/2018/x/psets/7/finance/finance.html#hints – Blauelf Jul 9 '18 at 13:50
  • @Blauelf it returns none if the username already exists ..so not of none is true ..im not sure where im going wrong ..? – user21692 Jul 9 '18 at 14:54
  • I meant the session["user_id"] = result[0]["id"]. Since INSERT causes db.execute to return the primary key, this should be just session["user_id"] = result. Case of VALUES does not matter, though. – Blauelf Jul 10 '18 at 7:25
  • The "please enter all details" condition requires not (A and B and C) or not A or not B or not C – Blauelf Jul 10 '18 at 7:31

You must log in to answer this question.

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