Reputation: 1
I have to enter string variable and int variable together in mysql Update statement using python
My code is as:
z=input("enter name:")
u=int(input("enter id"))
sn='update table1 set colname:"%s" where colid=%s'%z
cursor.execute(sn,(u,))
mydb.commit()
In the code I have given above colname
should get string value means user name and colid
should get int value means id in numbers. But after all these commands I get error:
Error: Not enough arguments for string
I can't understand why I am getting error as for string variable we have to use "%s"
in mysql statement and give its value to %z
after statement as I have given and for int variable in where
clause we have to give its variable in brackets as I have given above.
Note: When I replace colid
's %s
with a constant integer and remove (u,)
from execute
statement then the code runs correctly without any errors.
Upvotes: 0
Views: 411
Reputation: 782693
Put both variables in the cursor.execute()
call.
sn='update table1 set colname = %s where colid=%s'
cursor.execute(sn, (z, u))
Upvotes: 1