0

I'm getting an error with the following code:

class SomePage:
    def GET(self,name):
        conn = sqlite3.connect('./DB/ershou.db')
        LjDB = conn.cursor()
        searcher = web.input()
        DBsearch = LjDB.execute("select * from caiji where post like '%%%s%%'"%(searcher))
        for ss in DBsearch:
            print ss[1],
            print ss[2]
        return searcher.name

This is the error I'm talking about:

OperationalError: near "name": syntax error

What is causing this error, and how do I fix it?

1 Answer 1

3

Don't use string interpolation, especially when taking input from the web! Learn the lesson Little Bobby Tables teaches and use SQL parameters:

DBsearch = LjDB.execute("select * from caiji where post like ?", 
                        ('%{}%'.format(searcher),))

This is safer, faster, and more flexible.

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.