title: UnboundLocalError:local variable 'cursor' referenced before assignment
body: <p>So I am a newbie but working on a registration system form in flask/MYSQL</p>
  
  <p>I am receiving this error (UnboundLocalError: local variable 'cursor' referenced before assignment) only when I tried to update it from webpage.</p>
  
  <p>when I use postman its fine.</p>
  
  <p>After hours of playing with the code and research I need your help.</p>
  
  <p>This is my file, please let me know if theres anything else I need to share. thank you</p>
  
  <pre><code>@app.route('/updateHdd', methods=['POST'])
  def updateHdd():
  try:
      if session.get('user'):
          _user = session.get('user')
          _keterangan = request.form['editKeterangan']
          _nomor = request.form['nomor']
  
  
  
          conn = mysql.connect()
          cursor = conn.cursor()
          cursor.callproc('sp_updateHdd',(_user,_keterangan,_nomor))
          data = cursor.fetchall()
  
          if len(data) is 0:
              conn.commit()
              return json.dumps({'status':'OK'})
          else:
              return json.dumps({'status':'ERROR'})
  except Exception as e:
      return json.dumps({'status':'Unauthorized access'})
  finally:
      cursor.close()
      conn.close()    
  </code></pre>
  
  <p>here is my script in html:</p>
  
  <pre><code>$(function(){
  
              GetItems();
              $('#btnUpdate').click(function(){
                  $.ajax({
                      url : '/updateHdd',
                      data : { 
                          keterangan: $('#editKeterangan').val(),
                          nomor: localStorage.getItem('editNomor')
                      },
                  type : 'POST',
                  success: function(res){
                      $('#edit').modal('hide');
                  },
                  error: function(error){
                      console.log(error);
                  }
                  });
              });
          });
  </code></pre>
  
  <p>another script incase you you guys need:</p>
  
  <pre><code>function Edit(elm){
          localStorage.setItem('editId',$(elm).attr('data-id'));
              $.ajax({
                  url : '/getWishBynomor',
                  data : {id:$(elm).attr('data-id')},
                  type : 'POST',
                  success: function(res){
                      var data = JSON.parse(res);
                      $('#editKeterangan').val(data[0]['Keterangan']);
                      $('#editModal').modal();
                  },
                  error: function(error){
                      console.log(error);
                  }
              });
          }
  </code></pre>
  
  <p>and this is the html code:</p>
  
  <pre><code>&lt;div class="modal fade" id="editmodal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true"&gt;
          &lt;div class="modal-dialog"&gt;
              &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header"&gt;
                      &lt;button type="button" class="close" data-dismiss="modal"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;span class="sr-only"&gt;Close&lt;/span&gt;&lt;/button&gt;
                      &lt;h4 class="modal-title" id="editModalLabel"&gt;Update Data&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      &lt;form role="form"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="message-text" class="control-label"&gt;Keterangan:&lt;/label&gt;
                              &lt;textarea class="form-control" id="editKeterangan"&gt;&lt;/textarea&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-footer"&gt;
                      &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
                      &lt;button id="btnUpdate" type="button" class="btn btn-primary"&gt;Update&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I really need your help guys</p>