简体   繁体   中英

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 seem to be trying to convert a string to an 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. 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:

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 (). If you do it, you get a touple with a string, not a string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question 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 ') “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” 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")\' 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 '*) 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 error(1064, "check the manual that corresponds to your MySQL server version for the right syntax to use near 'default) VALUES 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): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use You have an error in your SQL syntax; check the manual that corresponds to your MySQL server PYTHON 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM