[英]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 ')
[英]FIX “Check the manual that corresponds to your MySQL server version for the right syntax to use near '%s”
以下代碼適用於插入查詢,但不適用於更新和刪除。
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'
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
:
a=int(input("Enter the new name : "))
這可能不適用於您的表格布局。
嘗試:
a=input("Enter the new name : ")
這不是no的拼寫,它是一個保留字。 這似乎是有效的:
UPDATE product SET myname = 'string', myprice = 123 WHERE myno = 1;
(當然,您需要更改數據庫表中的列名才能正常工作)
您使用 NO 作為列名,但它是 MySql 保留字,您應該像這樣對 sql_1 和 sql_2 使用反引號:
sql_1="select * from product where `No`=%s"
sql_2="update product set name=%s ,price=%s where `NO`=%s"
但更好的解決方案是不使用保留字作為列名。
編輯
此外,您的 sql_1 查詢是錯誤的,您不需要使用 ()。 如果你這樣做,你會得到一個帶有字符串的touple,而不是字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.