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
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
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
. Reference: MySQLdb User's Guide..execute()
is expected to be a sequence (e.g. tuple, list,...)Change your query to:
c.execute('''INSERT INTO Users (Username, FirstName, LastName, Balance)
VALUES (%s,%s,%s,%s)''', (Username, FirstName, LastName, Balance))
# ^^ ^^ ^^ ^^ ^ ^
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments