Edison Augusthy
Edison Augusthy

Reputation: 1573

syntax error on mysql query to update in python

here is my query

 x.execute("UPDATE details SET name =%s,"(form.newname)"WHERE name =%s," (form.name))

am getting syntax error.can anyone pls help to fix it

Upvotes: 0

Views: 281

Answers (3)

Harsha Biyani
Harsha Biyani

Reputation: 7268

You can try :

x.execute("""UPDATE details SET name = "%s" WHERE name = "%s" """, (form.newname, form.name))

If form.newname and form.name are TEXT fields in database, you have to pass %s with parenthesis "%s"

Upvotes: 0

Simon PA
Simon PA

Reputation: 746

Based on syntax: cursor.execute(sql_query, args)

It should be like:

x.execute("UPDATE details SET name = %s WHERE name = %s", (form.newname, form.name))

Upvotes: 1

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32003

If you want to update those name which is ending with the letter "s"

then you have to use LIKE operator in where clause

update destails set name ="adfsf" where name like '%s' 

Upvotes: 0

Related Questions