title: accessing MySQL database in XAMPP through flask framework
body: <p>I just started looking into Flask framework for a pet project of mine, and so, I have been working on a tutorial in envato tutsplus. I build the database in MySQL present in the XAMPP server and I am trying to access it, but I do not know how to go about doing it.</p>
  
  <p>I get this error in the chrome console <code>Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)</code>. I have already started XAMPP prior to executing this code.</p>
  
  <p>I know that the <code>@app.route('/signUp',methods=['POST','GET'])</code> is the key method to look into and also the key lies in <code>app.config['MYSQL_DATABASE_HOST']</code>. I thought that putting localhost as a value would work, but that is not the case and so I tried different values like <code>http://localhost:80</code> etc but that does not seem to work. What is it that I am missing? Please help me out</p>
  
  <p>Here is the backend code :</p>
  
  <pre><code>from flask import Flask, render_template, request, json
  from flask_mysqldb import MySQL
  from werkzeug import generate_password_hash, check_password_hash
  
  mysql = MySQL()
  app = Flask(__name__)
  
  # MySQL configurations
  app.config['MYSQL_DATABASE_USER'] = 'root'
  app.config['MYSQL_DATABASE_PASSWORD'] = ''
  app.config['MYSQL_DATABASE_DB'] = 'BucketList'
  app.config['MYSQL_DATABASE_HOST'] = 'localhost'
  mysql.init_app(app)
  
  @app.route('/')
  def main():
      return render_template('index.html')
  
  @app.route('/showSignUp')
  def showSignUp():
      return render_template('signup.html')
  
  @app.route('/signUp',methods=['POST','GET'])
  def signUp():
      try:
          _name = request.form['inputName']
          _email = request.form['inputEmail']
          _password = request.form['inputPassword']
  
          # validate the received values
          if _name and _email and _password:
  
          # All Good, let's call MySQL
  
              conn = mysql.connect()
              cursor = conn.cursor()
              _hashed_password = generate_password_hash(_password)
              cursor.callproc('sp_createUser',(_name,_email,_hashed_password))
              data = cursor.fetchall()
  
          if len(data) is 0:
              conn.commit()
              return json.dumps({'message':'User created successfully !'})
          else:
              return json.dumps({'error':str(data[0])})
          else:
              return json.dumps({'html':'&lt;span&gt;Enter the required fields&lt;/span&gt;'})
  
  except Exception as e:
      return json.dumps({'error':str(e)})
  finally:
      cursor.close() 
      conn.close()
  
  if __name__ == "__main__":
      app.run(port=5002)
  </code></pre>