0

我的程序有问题。我有两种形式,一种用于在数据库中搜索条目,另一种用于从数据库中获取数据并更新表单。我无法将搜索结果填充到同一页面上的下一个表单中。 在此处输入图像描述

    {% for row in records %}
                              <div class="form-group row">
                                 <label for="badgeId" class="col-sm-4 col-form-label">Scan Badge ID</label>
                                 <div class="col-sm-5">
                                    <input type="number" class="form-control" id="badgeId" name="badgeId"  value="{{row[0]}}">
                                 </div>
                              <div class="col-sm-3">
                                  <button type="submit" class="btn btn-primary" id="searchButton">Search</button>
                                 </div>
                              </div>
                              <br/>
                                  <div class="form-group row">
                                 <label for="fullName" class="col-sm-4 col-form-label">Full Name</label>
                                 <div class="col-sm-7">
                                    <input type="text" class="form-control" id="fullName"  value="{{row[1]}}" />
                                 </div>
                              </div>
                              <div class="form-group row">
                                 <label for="testDate" class="col-sm-4 col-form-label">Date</label>
                                 <div class="col-sm-7">
 
                                    <input type="text" class="form-control" id="testDate" value="{{row[2]}}" />
                                 </div>
                              </div>
                              <div class="form-group row">
                                 <label for="evidence" class="col-sm-4 col-form-label">Evidence Type</label>
                                 <div class="col-sm-7">
                                    <input type="text" class="form-control" id="evidence" value="{{row[3]}}" />
                                 </div>
                              </div>
                              <div class="form-group row">
                                 <label for="testLab" class="col-sm-4 col-form-label">Test Lab</label>
                                 <div class="col-sm-7">
                                    <input type="text" class="form-control" id="testLab"  value="{{row[4]}}"/>
                                 </div>
                              </div>

                               <div class="form-group row">
                                 <label for="testLab" class="col-sm-4 col-form-label">Test Status</label>
                                 <div class="col-sm-7">
                                    <input type="text" class="form-control" id="testStatus"  />
                                 </div>
                              </div>
                              </form>

  {% endfor %}

和 main.py 文件一样;

@app.route('/fetch', methods=['POST', 'GET'])
def fetch():
    Id = request.form['Id']
    cursor = mysql.connection.cursor()

    if request.method == 'POST':
        search_word = request.form['Id']
        print(search_word)
        sql_select_Query = "select * from employee_detail where badge_id = {}".format(badgeId)
        cursor.execute(sql_select_Query)
        records = cursor.fetchall()
        print(records)
    return render_template("display.html",records=records)
4

0 回答 0