i am flask starter. i was trying to loop through my mysql table data to check if the data in my form exist or i insert the form request in the table
this is what i have tried but it only keep saving without comparing
`@app.route('/createHotel', methods=['GET', 'POST'])`
`def createHotel():`
`names=''`
`if "loggedin" in session and 'admin'==session['role']:`
`user = session["username"`]
`userid = session["userid"]`
`cur.execute('SELECT name FROM hotels')`
`h = cur.fetchall()`
`i = 0
while i < len(h):
names=(h[i])
i = i + 1`
`if request.method == "POST" and 'name' in request.form and 'image' in request.form and 'city' in request.form:`
`image = request.form["image"`]
`name = request.form['name']`
`city = request.form['city']`
`features = request.form['features']`
`RoomCount = request.form['RoomCount']`
`peakSeasonRate = request.form['peakSeasonRate']`
`OffPeakSeasonRate = request.form['OffPeakSeasonRate']`
`if name != names:`
`cur.execute('INSERT INTO hotels (image, name, city, features, RoomCount, peakSeasonRate, OffPeakSeasonRate) VALUES (%s, %s, %s, %s, %s, %s, %s)', (image, name, city, features, RoomCount, peakSeasonRate, OffPeakSeasonRate))`
`mysql.connection.commit()`
`cur.close()`
`flash('hotel added successfully', 'success')`
`return redirect(url_for('hotelRecord'))`
`else`:
`flash('hotel already exist in the database', 'success')`
`return render_template("createHotel.html", user=user, userid=userid,)`
`return redirect(url_for("home"))`