Python MySQLdb寄存器程序?

Python MySQLdb寄存器程序?,python,mysql,mysql-python,Python,Mysql,Mysql Python,所以我和一个朋友正试图一起学习MySQLdb,我们从一个注册程序开始。下面是当前的代码: import MySQLdb import sys import time db = MySQLdb.connect(host="localhost",port=3306,user="root",passwd="",db="testing" ) cur = db.cursor() def register(): print "Welcome to user registration!"

所以我和一个朋友正试图一起学习MySQLdb,我们从一个注册程序开始。下面是当前的代码:

import MySQLdb
import sys
import time

db = MySQLdb.connect(host="localhost",port=3306,user="root",passwd="",db="testing" )
cur = db.cursor()

def register():
    print "Welcome to user registration!"
    user = raw_input("Username: ")
    passw = raw_input("Password: ")
    confpass = raw_input("Confirm password: ")
    if confpass.lower() != passw.lower():
        print "Passwords do not match!"
        register()
    print "Almost done!"
    email = raw_input("E-mail: ")
    confemail = raw_input("Confirm E-mail: ")
    if email.lower() != confemail.lower():
        print "Emails do not match!"
        register()
    add_user = ("INSERT INTO testing1 "
                "username, password"
                "VALUES (%s, %s)")

    data_test = (user, passw)
    cur.execute(add_user, data_test)
    db.close()

choice = raw_input("Do you want to register or login?: ")
if choice.lower() == 'register':
    register()

db.close()
我看了一些文档,但没有发现遗漏的内容。
我的数据库名为testing,表名为testing1,只有用户名(varchar 25)和密码(text)值。我做错了什么

编辑:回溯

Traceback (most recent call last):
  File "MySQLTesting.py", line 54, in <module>
    register()
  File "MySQLTesting.py", line 33, in register
    cur.execute(add_user, data_test)
  File "C:\Panda3D-1.8.0\python\lib\site-packages\MySQLdb\cursors.py", line 202,
 in execute
    self.errorhandler(self, exc, value)
  File "C:\Panda3D-1.8.0\python\lib\site-packages\MySQLdb\connections.py", line
36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax
; check the manual that corresponds to your MySQL server version for the right s
yntax to use near 'username, passwordVALUES ('Thing', 'idk')' at line 1")
回溯(最近一次呼叫最后一次):
文件“MySQLTesting.py”,第54行,在
寄存器()
寄存器中第33行的文件“MySQLTesting.py”
当前执行(添加用户、数据测试)
文件“C:\Panda3D-1.8.0\python\lib\site packages\MySQLdb\cursors.py”,第202行,
执行中
errorhandler(self、exc、value)
文件“C:\Panda3D-1.8.0\python\lib\site packages\MySQLdb\connections.py”,第行
36,在defaulterrorhandler中
提高errorclass,errorvalue
_mysql_exceptions.ProgrammingError:(1064),“您的SQL语法有错误
;查看与您的MySQL服务器版本对应的手册,以获取正确的
yntax在第1行使用“用户名、密码值('Thing'、'idk')”附近)
根据要求,您应该将列名用括号括起来:

add_user = "INSERT INTO testing1 (username, password) VALUES (%s, %s)"

从错误消息中,我猜您需要在用户名、密码之后加空格,或者在值之前加空格。事实并非如此,我尝试了这两种方法,但都出现了相同的错误。