title: How can I validate email and username on my registration form. I am using flask and mysqlalchemy
body: <p>Here is my route which works great problem is i can register same user many many times:</p>
  <pre><code>@app.route('/register', methods=['GET', 'POST'])
  def register():
      if request.method == 'POST':
          name = request.form.get('name')
          username = request.form.get('username')
          email = request.form.get('email')
          password = request.form.get('password')
          confirm = request.form.get('confirm')
          secure_password = sha256_crypt.encrypt(str(password))
  
          if password == confirm:
              db.execute('INSERT INTO users(name, username, email, password) VALUES(:name,:username,:email,:password)',
                                             {'name':name,'username':username,'email':email,'password':secure_password})
              db.commit()
              flash(&quot;you are registerd and you can login&quot;,&quot;success&quot;)
              return redirect(url_for('login'))
          else:
              flash(&quot;password does not match&quot;,&quot;danger&quot;)
              return render_template('register.html')
  
      return render_template('register.html')
  </code></pre>