title: How to solve this bad key error in flask?
body: <p>I am trying to enter values in form and fetch values from database but I am not able to do that.I am using mysql database named as travel and table is also named as travel.I am attaching my python code and template below
  My error is:werkzeug.exceptions.BadRequestKeyError
  werkzeug.exceptions.HTTPException.wrap..newcls: 400 Bad Request: KeyError: 'stay'</p>
  
  <p>Python Code:</p>
  
  <pre><code>from flask import Flask, render_template, request, redirect,flash,url_for,session
  from flask_mysqldb import MySQL
  import datetime
  import time
  app = Flask(__name__)
  app.config['MYSQL_HOST'] = "127.1.1.0"
  app.config['MYSQL_USER'] = "root"
  app.config['MYSQL_PASSWORD'] = "****"
  app.config['MYSQL_DB'] ="travel"
  app.secret_key="gsabo"
  mysql = MySQL(app)
  @app.route('/')
  @app.route('/questions',methods=['GET', 'POST'])
  def questions():
      if request.method == "POST" or "GET":
          userDetails= request.form
          cur = mysql.connection.cursor()
          stay=userDetails['stay']
          Budget=userDetails['Budget']
          print(Passengers,Weather,Transport,stay,Interests)
          cur.execute("select * from travel where stay=%s,Budget=%s",(stay,Budget,))
          mysql.connection.commit()
          userDetails=cur.fetchone()
          Location=userDetails[3]
          Budget=userDetails[4]
          return render_template('questions.html',Budget=Budget,Location=Location)
      return render_template('questions.html')
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>Template in HTML:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
      &lt;title&gt;Travel&lt;/title&gt;
      &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="content"&gt;
  &lt;form action="/questions" method="post"&gt; 
  &lt;table&gt;
              &lt;tr&gt;&lt;th colspan="2"&gt;Find Travel Detination and Budget&lt;/th&gt;&lt;/tr&gt;
                  &lt;tr&gt;  
                      &lt;td&gt; stay&lt;font color='red'&gt;*&lt;/font&gt; :&lt;/td&gt;  
                      &lt;td&gt;&lt;select name="stay"&gt;
                          &lt;option&gt;Select&lt;/option&gt;
              &lt;option value="Hotel"&gt;Hotel&lt;/option&gt;
              &lt;option value="Tent"&gt;Tent&lt;/option&gt;
              &lt;/select&gt;&lt;/td&gt;  
                  &lt;/tr&gt;  
  
  
                  &lt;tr&gt;  
                      &lt;td&gt;Budget&lt;font color='red'&gt;*&lt;/font&gt; :&lt;/td&gt;  
                      &lt;td&gt;&lt;select name="Budget"&gt;
                          &lt;option&gt;Select&lt;/option&gt;
              &lt;option value="1000"&gt;1000$&lt;/option&gt;
              &lt;option value="2000"&gt;2000$&lt;/option&gt;
              &lt;option value="3000"&gt;3000$&lt;/option&gt;
              &lt;option value="4000"&gt;4000$&lt;/option&gt;
              &lt;option value="5000"&gt;5000$&lt;/option&gt;
              &lt;option value="6000"&gt;6000$&lt;/option&gt;
              &lt;option value="7000"&gt;7000$&lt;/option&gt;
              &lt;option value="8000"&gt;8000$&lt;/option&gt;
              &lt;option value="9000"&gt;9000$&lt;/option&gt;
              &lt;option value="10000"&gt;10000$&lt;/option&gt;
              &lt;/select&gt;&lt;/td&gt;  
                  &lt;/tr&gt;
  
                      &lt;td&gt;&lt;input type="submit" value="Submit" href="hello" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="reset" value="Reset" /&gt;&lt;/td&gt;  
                  &lt;/tr&gt;  
          &lt;tr&gt;  
                      &lt;td&gt;Budget:&lt;/td&gt;  
                      &lt;td&gt;&lt;input type="number" name="Budget" value="&lt;%=Budget %&gt;" readonly disabled/&gt;&lt;/td&gt;  
                  &lt;/tr&gt; 
                  &lt;tr&gt;  
                      &lt;td&gt;Location:&lt;/td&gt;  
                      &lt;td&gt;&lt;input type="text" name="Location" value="&lt;%=Location %&gt;" readonly disabled/&gt;&lt;/td&gt;  
                  &lt;/tr&gt;  
  &lt;/form&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>