0

I am executing the command

light='L1'
status='on'
c.execute("UPDATE my_table SET %s=%s WHERE user IN('Ali')", (light,status))

it throws me an error:

(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''L2'='OFF' WHERE user IN('Ali')' at line 1")

Can anyone find out where i am doing the mistake.

I tried to find the similar question on Stack overflow website, but couldn't got any help. So kindly don't mark it as duplicate if anyone find it out.

1 Answer 1

3

i think you should get rid of quote signs here:

''L2'

as MySQL said:

near ''L2'='OFF' WHERE user IN('Ali')

Here we go:

light='L1'
status='on'
sql = "UPDATE my_table SET %s=%%s WHERE user IN('Ali')" %light
c.execute(sql, (status))
Sign up to request clarification or add additional context in comments.

2 Comments

Yes I observed the same thing, but how do i get rid of that ?,
you should NOT use column_names as parameters in the "execute" function

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.