title: TypeError: 'ResultProxy' object does not support indexing when trying to store user ID in sessions
body: <p>In my <code>Signedup</code> route I am trying to store user id in session and log users in automatically but when I try to do so I get this error:</p>
  
  <p><code>TypeError: object of type 'ResultProxy' does not support indexing</code></p>
  
  <p>And, In my <code>signin</code> route I am trying to remember which user has logged in but here I get error:</p>
  
  <p><code>TypeError: object of type 'ResultProxy' has no len()</code></p>
  
  <p><code>signedup</code> route in <code>application.py</code></p>
  
  <pre><code>@app.route("/signedup",methods=["GET","POST"])
  def signedup():
      if request.method=="POST":
          password = request.form.get("password")
          hash = pwd_context.encrypt(password)
  
  
          name = request.form.get("name")
  
  
  
          if not name:
              return "must provide username"
          elif not password:
              return "must provide password"
  
  
  
          registration = db.execute("INSERT INTO users (username,password) VALUES (:username,:password)",
                      {"username":name,"password":hash})
  
          if not registration:
              return "pick a different username"
  
  
          # Store their ID in session and log them in automatically
  
       user_id = db.execute("SELECT user_id FROM users where username = :username",{"username":name})        
              # It means something like - "give me the first row in result
  
              # and retrieve the value of the key "id"
  #ERROR
              session["user_id"] = user_id[0]["id"]      
              db.commit()
  
              return render_template("success.html",name = name)
          else:
              return render_template("signup.html")
  </code></pre>
  
  <p><code>signin</code> route in <code>application.py</code></p>
  
  <pre><code>@app.route("/signin",methods=["GET","POST"])
  def signin():
      # LOG A USER IN
      #forget any user_id
      session.clear()
  
      if request.method == "GET":
          return render_template("login.html")
  
      else:
          user_name = request.form.get("username")
  
          # ensure username is provided
          if not request.form.get("username"):
              return "must provide username"
  
          # ensure password is provided
          elif not request.form.get("password"):
              return "must provide password"
  
  
          # query the database for the username
          rows = db.execute("SELECT * FROM users where username = :username",{"username":user_name})
  
          # ensure username exists 
          if len(rows) != 1 or not pwd_context.verify(request.form.get("password"),rows[0]["hash"]):
              return "Invalid username"
  
          # remember which user has logged in 
          session["user_id"] = rows[0]["id"]
  </code></pre>