title: Python Flask - " Check if the username exists in the MySQL database"
body: <p>I am running a python Flask application which takes a username and password.  I wanted to check if the username exists on the Mysql database. If it does, I wanted to return " username exists" on the web page.</p>
  
  <p>below is my flask code:</p>
  
  <pre><code>from flask import Flask,render_template,request,redirect
  from flask_mysqldb import MySQL
  import yaml
  
  app = Flask(__name__)
  
  db = yaml.load(open('db.yaml'))
  app.config['MYSQL_HOST'] = db['mysql_host']
  app.config['MYSQL_USER'] = db['mysql_user']
  app.config['MYSQL_PASSWORD'] = db['mysql_password']
  app.config['MYSQL_DB'] = db['mysql_db']
  
  mysql =MySQL(app)
  
  @app.route('/', methods=['GET','POST'])
  def index():
  
      if request.method == 'POST' and request.method=='GET':
          #fetch form data
          userdetails = request.form
          name = userdetails['name']
          email = userdetails['email']
          cur = mysql.connection.cursor()
          new_value= cur.execute("SELECT (name,email) FROM users where name = %s and email=%s",'name','email')
          if new_value&gt; 0:
              return "the username exists"
          else:
              return "SUCCESS!,Successfully entered into the Database"
  
      return render_template('index.html')
  </code></pre>
  
  <hr>
  
  <p>when i run the flask application, my web page doesnt return anything.</p>