title: FLASK HTML field for Mysql query
body: <p>Hello Stackoverflow community,</p>
  
  <p>I am new to FLASK however while the learning curve has been very steep, there is one item that I have not been able to get my head around.</p>
  
  <p>I am using a very simple HTML seach form, into which users type the name of a city, this input gets passed to a Mysql query and returns output into a Table.</p>
  
  <p>Everything works except that I can't get the variable to pass into Mysql... if I fix the query it works.</p>
  
  <p>I tried to work with FLASK WTForms, POST and GET requets, but I don't know where I am going wrong.
  The variable data that I am passing is not confidencial, so I have no concern if it shows up in the URL.</p>
  
  <p>Here just the simple FORM (I guess not correct)</p>
  
  <pre><code>  &lt;form&gt;
  &lt;div class="form-group"&gt;
      &lt;div class="col-sm-3"&gt;
          &lt;input type="text" placeholder="City Name" name="City_Name" action=/search class="form-control"&gt;
      &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;div class="col-sm-2"&gt;
          &lt;input type="submit" value="SEARCH" class="btn btn-primary btn-block"&gt;
      &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here the table output (working perfectly)</p>
  
  <pre><code>&lt;table class="table table-striped"&gt;
  
  
              &lt;tr&gt;
                &lt;th&gt;PO_Number&lt;/th&gt;
                &lt;th&gt;Plant Name&lt;/th&gt;
                &lt;th&gt;GMID&lt;/th&gt;
                &lt;th&gt;Material&lt;/th&gt;
                &lt;th&gt;INCOTERM&lt;/th&gt;
                &lt;th&gt;Vendor&lt;/th&gt;
                &lt;th&gt;Vendor Count&lt;/th&gt;
              &lt;/tr&gt;
  
  
             {% for row in tabledata %}
             &lt;tr&gt;
  
               &lt;td&gt;{{ row['PO_Number'] }}&lt;/td&gt;
               &lt;td&gt;{{ row['PN'] }}&lt;/td&gt;
               &lt;td&gt;{{ row['GD'] }}&lt;/td&gt;
               &lt;td&gt;{{ row['MN'] }}&lt;/td&gt;
               &lt;td&gt;{{ row['INCO'] }}&lt;/td&gt;
               &lt;td&gt;{{ row['VNGS'] }}&lt;/td&gt;
               &lt;td&gt;{{ row['CVNGS'] }}&lt;/td&gt;
             &lt;/tr&gt;
             {% endfor %}
  
     &lt;/table&gt;
  </code></pre>
  
  <p>Here the Python code</p>
  
  <pre><code>from flask import Flask, render_template, request, url_for
  from dbhelper_single_search import DBHelper
  
  
  app = Flask(__name__)
  DB = DBHelper()
  
  
  @app.route('/table')
  def table():
      try:
          tabledata = DB.table_inputs()
      except Exception as e:
          print(e)
          tabledata = None
      return render_template("table.html", tabledata=tabledata)
  
  
  if __name__ == '__main__':
      app.run(port=5000, debug=True)
  </code></pre>
  
  <p>Data Base Helper Mysql (the valye for PLN should change based on the input in the Form.</p>
  
  <pre><code>import pymysql
  class DBHelper:
  
  def table_inputs(self):
          connection = self.connect()
          PLN="**City_Name**"
          try:
              query = "SELECT Plant_Geo, Plant_Code, Plant_Name, GMID, Material_Name, GROUP_CONCAT(DISTINCT Vendor_Name_GS ORDER BY Vendor_Name_GS) as VNGS, sum(2014_USD), sum(2015_USD), sum(2016_USD) FROM invoice_report WHERE plant_code like '%s' GROUP BY GMID ORDER BY sum(2015_USD) DESC" %(PLN);
              with connection.cursor(pymysql.cursors.DictCursor) as cursor:
                  cursor.execute(query)
              return cursor.fetchall()
          finally:
              connection.close()
  </code></pre>
  
  <p>Thank you in advance for any help.</p>