[英]MySQL: 1064 Syntax Error
Hi I am working on a small program to store usernames and real names and I want to use MySQL this is my first time using it and I am following a tutorial but they have done the same as me but I get the error message below 嗨,我正在开发一个用于存储用户名和真实姓名的小程序,我想使用MySQL,这是我第一次使用它,我正在学习一个教程,但是它们的操作与我相同,但出现以下错误消息
1064, "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 ''
I am also not sure which line the problem is as it just says '' 我也不确定问题出在哪一行,因为它只是说''
Here is my current code, when I copy the execute code into phpMyAdmin it runs when I add values 这是我当前的代码,当我将执行代码复制到phpMyAdmin中时,它会在我添加值时运行
import MySQLdb
Users = MySQLdb.connect('sql-.freemysqlhosting.net', 'sql4---16', 'uY---R5*', 'sql4---16')
c = Users.cursor()
Username = raw_input('Enter Username: ')
FirstName = raw_input('Enter first name: ')
LastName = raw_input('Enter last name: ')
Balance = raw_input('Enter deposit: ')
c.execute('INSERT INTO Users (Username, FirstName, LastName, Balance) VALUES (?,?,?,?)',
Username, FirstName, LastName, Balance)
Users.commit()
Users.close()
There are two problems with your code. 您的代码有两个问题。
%s
. MySQLdb中的默认“ paramstyle”是%s
。 Reference: MySQLdb User's Guide . 参考:《 MySQLdb用户指南》 。 .execute()
is expected to be a sequence (eg tuple, list,...) .execute()
的第二个参数应该是一个序列(例如,元组,列表等) Change your query to: 将查询更改为:
c.execute('''INSERT INTO Users (Username, FirstName, LastName, Balance)
VALUES (%s,%s,%s,%s)''', (Username, FirstName, LastName, Balance))
# ^^ ^^ ^^ ^^ ^ ^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.