-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)
AlexInCube
  • 69
  • 6
  • Your select query should include the "score" field. In this way: `SELECT UserID,score FROM userdata` – Arash Jul 28 '21 at 19:22

1 Answers1

3

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

so make

cur.execute(query, (user_id,))
nbk
  • 45,398
  • 8
  • 30
  • 47