简体   繁体   English

修复“查看与您的 MySQL 服务器版本相对应的手册,以获取在 '%s 附近使用的正确语法”

[英]FIX “Check the manual that corresponds to your MySQL server version for the right syntax to use near '%s”

The following code works with insert query, but not with update and 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")

The error I'm getting is 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' 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 seem to be trying to convert a string to an int :您似乎正在尝试将string转换为int

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

This probably is not working with your table layout.这可能不适用于您的表格布局。

Try:尝试:

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


Also you are using "No" and "NO" in your queries. 此外,您在查询中使用“否”和“否”。


It's not the spelling of no, it's a reserved word.这不是no的拼写,它是一个保留字。 This seems to be valid:这似乎是有效的:

 UPDATE product SET myname = 'string', myprice = 123 WHERE myno = 1;

(of course you need to change your column names in the database table for this to work) (当然,您需要更改数据库表中的列名才能正常工作)

You are using NO as column name, but is a MySql reserved word, you should use backticks for it like this for sql_1 & sql_2:您使用 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"

But the better solution it is not using reserved words as column names.但更好的解决方案是不使用保留字作为列名。

EDIT编辑

Also, your sql_1 query is wrong, you don´t need to use ().此外,您的 sql_1 查询是错误的,您不需要使用 ()。 If you do it, you get a touple with a string, not a string如果你这样做,你会得到一个带有字符串的touple,而不是字符串

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在 ') 附近使用的正确语法 - 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 ') “你的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在''第1行'附近使用正确的语法 - “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 '' at line 1” 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在 \'keyword")\' 附近使用的正确语法 - 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 \'keyword")\' 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在 '*) 附近使用的正确语法 - 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 '*) 警告:您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法 - Warning: 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 _mysql_exceptions错误(1064,“检查与MySQL服务器版本对应的手册,以便在'default'附近使用正确的语法)VALUES - _mysql_exceptions error(1064, "check the manual that corresponds to your MySQL server version for the right syntax to use near 'default) VALUES 您的SQL语法有错误; 检查与您的MariaDB服务器版本对应的手册,以便在第1行附近使用正确的语法, - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near at line 1", 1064(42000):您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法使用 - 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use 您的 SQL 语法有错误; 检查与您的 MySQL 服务器 PYTHON 相对应的手册 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server PYTHON 42000您的SQL语法错误; 检查与您的MySQL服务器相对应的手册 - 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM