0

I am having this problem with my register function in pset9 when i register on the web app it says error 500 internal server error and when i check my terminal it says:

return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ubuntu/pset9/finance/application.py", line 136, in register
added_user = db.execute("INSERT INTO users (username, hash) VALUES(:username, 
:hash)", username=request.form.get("username"), hash_p=password_hash)
File "/usr/local/lib/python3.9/site-packages/cs50/sql.py", line 21, in 
decorator
return f(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/cs50/sql.py", line 215, in 
execute
raise RuntimeError("missing value for placeholder (:{})".format(name))
RuntimeError: missing value for placeholder (:hash)

This is the code for the register function:

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

if request.method == "POST":
    username = request.form.get("username")
    password = request.form.get("password")
    confirmation = request.form.get("confirmation")
    if not(username):
        return apology("Oops you need a username!")
    elif not(password) or not(confirmation):
        return apology("Oops you need a password!")
    elif password != confirmation:
        return apology("Oops password and confirmation password do not match")

    password_hash = generate_password_hash(password)
    added_user = db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash_p=password_hash)

    if not added_user:
        return apology("an account has already been registered with this username")

    session["user_id"] = added_user
    return redirect(url_for("index"))

else:
    return render_template("register.html")
1

The problem is simple. Your placeholder for hash in the sql insert statement is hash but then you have used hash_p instead of hash when assigning the value.

Hope this helps. If it does then please check the tickmark.

1
  • I just checked it and yes it does help out thank you for your help
    – Arsham
    Feb 27 at 9:31

You must log in to answer this question.

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