title: Getting the input from HTML form and storing it in mysql through Flask
body: <p>Am taking my first steps in python. Am using Flask framework and am writing a basic app that would take the input from the html form and store it in a table  MySql database. So this is what am doing</p>
  
  <p>The html form sample.html:</p>
  
  <pre><code> &lt;!DOCTYPE html&gt;
    &lt;html&gt;
    &lt;body&gt;
  
    &lt;form method="POST"&gt;
    First name: &lt;input type="text" name="fname"&gt;&lt;br&gt;
    Last name: &lt;input type="text" name="lname"&gt;&lt;br&gt;
    Email Id : &lt;input type="text" name="emailid"&gt;&lt;br&gt;
   &lt;input type="submit" value="Submit"&gt;
   &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The python script am using is:</p>
  
  <pre><code>from flask import Flask,request,render_template
  from flaskext.mysql import MySQL
  mysql=MySQL()
  
  app=Flask(__name__)
  app.config['MYSQL_DATABASE_USER']='root'
  app.config['MYSQL_DATABASE_PASSWORD']='root'
  app.config['MYSQL_DATABASE_DB']='names'
  app.config['MYSQL_DATABASE_host']='127.0.0.1:3306'
  mysql.init_app(app)
  
  @app.route('/',methods=['GET','POST'])
  def get_data():
   return render_template("sample.html")
    if request.method=='POST':
      first_name=request.form['fname']
      last_name=request.form['lname']
      emailid=request.form['emailid']
      connection = mysql.get_db()
      cursor = connection.cursor()
   query="INSERT INTO names_tbl(f_name,l_name,e_id) VALUES(%s,%s,%s)"
   cursor.execute(query,(first_name,last_name,email_id))
      connection.commit()
      return "nothing fucked"
  else:
      return("something fucked up")
  
  if __name__=='__main__':
  app.run(debug=True)
  </code></pre>