title: FLASK SQlite Python - Checking if username is already in database
body: <p>Hey can anyone tell me what I'm doing wrong in my code? I want to check whether an username is already in the database or not.</p>
  
  <p>Whole Route. It wont give me any errors but also wont fill my database.</p>
  
  <pre><code>@app.route('/regist', methods=['GET', 'POST'])
  def regist():
      if request.method == "POST":
          with sql.connect("database.db") as con:
              cur = con.cursor()
          try:
              # flash("register attempted")
  
              username = request.form['username']
              password = request.form['password']
              passwordencr = request.form['password']
              email = request.form['email']
  
              x = cur.execute("SELECT * FROM users WHERE name = ?", (username))
  
              if int(len(x)) &gt; 0:
                  flash("That username is already taken, please choose another")
                  return render_template('register.html')
              else:
                  cur.execute("INSERT INTO users (name,password,email) VALUES (?,?,?)",(username,passwordencr,email) )
  
                  con.commit()
                  flash ("Successfully registrated")
          except:
              con.rollback()
              msg = "error in insert operation"
  
          finally:
              session['logged_in'] = True
              session['username'] = username
              gc.collect()
              msg = Message('Hello', sender='yourId@gmail.com', recipients=[email])
              msg.body = "your username for ak047 is: %s and your password is %s" %(username,password)
              mail.send(msg)
              return render_template("home.html", msg=msg)
              con.close()
              gc.collect()
  </code></pre>