title: how to dynamicaly create table column names and insert values using flask and mysql
body: <p>I would like to create multiple text boxes based on the value given in a particular text box and another text box which will hold table name now I wanted to fetch the table name from the text box and also get the values given in the multiple text boxes as a column name and should create a database in MySQL.</p>
  
  <p>here is my py</p>
  
  <pre><code>from flask import Flask
  from flask import request
  from flask import render_template
  from flaskext.mysql import MySQL
  
  app = Flask(__name__)
  
  
  mysql = MySQL()
  app.config['MYSQL_DATABASE_USER'] = 'root'
  app.config['MYSQL_DATABASE_PASSWORD'] = 'root'
  app.config['MYSQL_DATABASE_DB'] = 'matrimony'
  app.config['MYSQL_DATABASE_HOST'] = 'localhost'
  mysql.init_app(app)
  
  
  @app.route('/')
  def index():
      return render_template('index1.html')
  
  
  @app.route('/searchQuery', methods=['POST'])
  def search_query():
      if request.method: "POST"
      conn = mysql.connect()
      cursor = conn.cursor()
      name=request.form.get('name')
      sq_ = request.form.get('searchQuery')
      x=request.form.get('x')
      cursor.execute("""CREATE TABLE `%s`( NAME VARCHAR(50) DEFAULT NULL) """ % (name))
      print(sq_)
  
      return render_template('simplesearch.html', search_query=sq_)
  
  
  
  if __name__ == '__main__':
      app.run() 
  </code></pre>
  
  <p>index1.html</p>
  
  <pre><code>&lt;form action="{{ url_for('search_query') }}" method="post"&gt;
      Name:&lt;input type="text"  name="name"&gt;
      Column Number:&lt;input type="text" name="searchQuery" id="searchQuery"&gt;&lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>simplesearch.html</p>
  
  <pre><code>&lt;table&gt;
      {% for x in range(search_query | int) %}
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;input type="text"  name="i{{ x }}"&gt;
                  &lt;input type="hidden" value="{{ search_query }}"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      {% endfor %}
  &lt;input type="submit" value="Submit"&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>It fetches table name from the tex tbox and only one column is created.
  Any help with this would be much grateful Thankyou </p>