title: Flask Registration Form Condition if elif else doesn't work
body: <p>When I try to register an user, I don't know why, but if the email I'm trying to register does not exist in the db, the for loop ends, though there's an elif end else statement.</p>
  
  <p>Someone know why?</p>
  
  <p>This is the web.py file</p>
  
  <pre><code>from flask import Flask, session, redirect, url_for, escape, request, render_template
  from wtforms import Form, BooleanField, TextField, PasswordField, validators
  import MySQLdb
  import logging
  
  
  app = Flask(__name__)
  
  
  db = MySQLdb.connect(host="127.0.0.1", user="root", passwd="usbw", port=3307, db="tourme")
  cur = db.cursor()
  
  
  @app.route('/register/', methods=["GET","POST"])
  def register():
  
      email_msg = None
      success_msg = None
      pass_msg = None
      test = None
  
      try:
  
          if request.method == 'POST':
  
              id_id = None
              username = request.form['name']
              lastname = request.form['lastname']
              email = request.form['email']
              password = request.form['password']
              repeat = request.form['repeat']
  
              cur = db.cursor()
              cur.execute("SELECT * FROM users WHERE email = (%s)", [email])
  
              for row in cur.fetchall():
                  if row[1] == email:
                      email_msg = "This e-mail already exist: " + row[1]
  
                  elif password == repeat:
                      cur.execute("INSERT INTO users VALUES (%s,%s,%s,%s,%s)", (id_id,email,username,lastname,password))
                      db.commit()
                      success_msg = "Bravo"
                      db.close()
  
                  else:
                      pass_msg = "Password must match"
  
          return render_template("register.html", email_msg=email_msg, success_msg=success_msg, pass_msg=pass_msg)
  
      except Exception as e:
          return(str(e)) 
  
  
  app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>And this is the template</p>
  
  <pre><code>&lt;div class="register"&gt;    
      &lt;form action="" method="POST"&gt;
          &lt;div class="input-group"&gt;
              &lt;span class="input-group-addon" id="basic-addon3"&gt;Your Username&lt;/span&gt;
              &lt;input type="text" class="form-control" name="name" aria-describedby="basic-addon3"&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;div class="input-group"&gt;
              &lt;span class="input-group-addon" id="basic-addon3"&gt;Your Lastname&lt;/span&gt;
              &lt;input type="text" class="form-control" name="lastname" aria-describedby="basic-addon3"&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;div class="input-group"&gt;
              &lt;span class="input-group-addon" id="basic-addon3"&gt;Email&lt;/span&gt;
              &lt;input type="email" class="form-control" name="email" aria-describedby="basic-addon3"&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;div class="input-group"&gt;
              &lt;span class="input-group-addon" id="basic-addon3"&gt;Your Password&lt;/span&gt;
              &lt;input type="password" class="form-control" name="password" aria-describedby="basic-addon3"&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;div class="input-group"&gt;
              &lt;span class="input-group-addon" id="basic-addon3"&gt;Repeat Password&lt;/span&gt;
              &lt;input type="password" class="form-control" name="repeat" aria-describedby="basic-addon3"&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;input type="Submit" value="Register" class="btn btn-default btn-sm"&gt;
      &lt;/form&gt;
      {% if success_msg %}
          &lt;p class=success_msg&gt;&lt;strong&gt;Message:&lt;/strong&gt; {{ success_msg }}
      {% endif %}
      {% if email_msg %}
          &lt;p class=success_msg&gt;&lt;strong&gt;Error:&lt;/strong&gt; {{ email_msg }}
      {% endif %}
      {% if pass_msg %}
          &lt;p class=pass_msg&gt;&lt;strong&gt;Error:&lt;/strong&gt; {{ pass_msg }}
      {% endif %}    
      &lt;br&gt;
      &lt;a href="{{ url_for('index') }}"&gt;Home&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks a lot for your help!</p>