以下代码适用于insert查询,但不适用于update和delete。在
prono=int(input("Enter the poduct no :"))
sql_1="select * from product where prno=%s"
mycursor.execute(sql_1,prono)
myresult=mycursor.fetchall()
mydb.commit()
for x in myresult:
print(x)
#details printed
#req. details for updation
print("Please enter the new details of the product")
a=str(input("Enter the new name : "))
b=int(input("Enter the new price : "))
sql_2="update product set name=%s ,price=%s where prno=%s"
set1=(a,b,prono)
mycursor.execute(sql_2,set1)
mydb.commit
print("Product modified")
我得到的错误是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 '%s'
您似乎试图将
string
转换为int
:这可能不适用于您的表格布局。在
尝试:
^{pr2}$另外,您在查询中使用“No”和“No”。
这不是“不”的拼写,是个保留字。这似乎是有效的:
(当然,您需要更改数据库表中的列名才能使其生效)
您使用NO作为列名,但它是MySql的保留字,对于sql_1和sql_2,应该使用反勾号:
但更好的解决方案是不使用保留字作为列名。在
编辑
另外,您的sql_1查询是错误的,您不需要使用()。如果你这么做,你会得到一个用绳子,而不是一根绳子的假发
相关问题 更多 >
编程相关推荐