0

I have a database and i want to search in it with this HTML

       <form action="/question/search" method="POST">
           <input id="search" type="text" placeholder="Search.." name="search">
           <button id="search" type="submit">&#x1F50D;</button>
      </form>

I get the data in my function

@app.route("/question/search",methods=["POST"])
def search():
    search_result = request.form.get("search")
    story = data_handler.get_search_result(search_result)
    return render_template('search_resoult.html', stories=story)

but i just cant figure out the SQl for it i tried :

@database_common.connection_handler
def get_search_result(cursor,item):
    my_sql = "SELECT * FROM question WHERE title LIKE %s OR message LIKE %s"
    my_resoult = (item)
    cursor.execute(my_sql, my_resoult)
    resoult = cursor.fetchall()
    return resoult

I just want to all the data that has my_result in the title or in the message. It always gives me this error:

TypeError: not all arguments converted during string formatting

1 Answer 1

1

The problem is that your query requires 2 values to be unpacked, but you're only giving a single one (item). If you want to use item as the condition for both title LIKE and message LIKE, you should expand my_resoult:

my_resoult = (item, item) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.