Python “固定”;查看与您的MySQL服务器版本对应的手册,以了解可在';%附近使用的正确语法s";

Python “固定”;查看与您的MySQL服务器版本对应的手册,以了解可在';%附近使用的正确语法s";,python,mysql,Python,Mysql,以下代码适用于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: prin

以下代码适用于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")

我得到的错误是
您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解在“%s”附近使用的正确语法。

您似乎正在尝试将
字符串
转换为
int

a=int(input("Enter the new name : "))
这可能不适用于您的表布局

尝试:


此外,您在查询中使用“否”和“否”


这不是“不”的拼写,而是一个保留字。这似乎是正确的:

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查询是错误的,您不需要使用()。如果你这么做了,你会得到一个有绳子的图尔,不是一个字符串。

ahh。。是的,我修复了,但它仍然存在。@tcadidot0这些都是通过
mycursor.execute(…)扩展的。
%s
来自哪里?
mycursor.execute(…)
下面两行。如果我的答案有效,请接受它,并向上投票它曾经有效,我不知道如何,…但现在不行…删除()后,确定,将此mycursor.execute(sql_1,prono)更改为此mycursor.execute(sql_1,(prono,)),您需要向execute发送一组参数
sql_1="select * from product where `No`=%s"

sql_2="update product set name=%s ,price=%s where `NO`=%s"