-3

I want to search for a user in a table by the user id from discord, but I can't provide the id in mysql. I get an error You have an error in your SQL syntax; But I don't understand what's wrong.

    @commands.command()
    async def balance(self, ctx):
        create_balance(ctx)
        query = ("SELECT UserID FROM userdata "
                 "WHERE UserID = %s")

        user_id = ctx.message.author.id
        cur.execute(query, (user_id))
        for (UserID, score) in cur:
            print(UserID,score)
1
  • Your select query should include the "score" field. In this way: SELECT UserID,score FROM userdata Commented Jul 28, 2021 at 19:22

1 Answer 1

3

in python in conjunction with mysql connector a tuple needs at least 2 dimensions

so make

cur.execute(query, (user_id,))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.