FIX“检查与MySQL服务器版本相对应的手册,了解在'%s'附近使用的正确语法”

2024-09-30 10:37:59 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: thenewforinputsqlupdateproductdetails
2条回答

您似乎试图将string转换为int

a=int(input("Enter the new name : "))

这可能不适用于您的表格布局。在

尝试:

^{pr2}$


另外,您在查询中使用“No”和“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查询是错误的,您不需要使用()。如果你这么做,你会得到一个用绳子,而不是一根绳子的假发

相关问题 更多 >

    热门问题