MySQL: 1064 Syntax Error

Sam Collins

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()
mechanical_meat

There are two problems with your code.

  1. The default "paramstyle" in MySQLdb is %s. Reference: MySQLdb User's Guide.
  2. The second argument to .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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQLSTATE[42000]: Syntax error or access violation: 1064 PHP/MySQL

From Dev

Mysql stored Procedure syntax error 1064

From Dev

Syntax error #1064

From Dev

Syntax Error MYSQL 1064

From Dev

MySQL Error 1064: You have an error in your SQL syntax

From Dev

mysql syntax ERROR 1064 while creating a trigger

From Dev

Python MYSQL Query throws programming syntax error 1064

From Dev

simple mysql function syntax error 1064

From Dev

Function call is returning MySQL Syntax Error 1064

From Dev

MySQL #1064 - You have an error in your SQL syntax

From Dev

MySQl Error #1064 Syntax error

From Dev

MySQL Trigger Syntax Error #1064

From Dev

MYSQL trigger syntax error. #1064

From Dev

Mysql stranger syntax error #1064

From Dev

MySQL: 1064 Syntax Error

From Dev

Mysql syntax error, 1064

From Dev

Syntax error #1064

From Dev

mysql syntax error 1064 (42000)

From Dev

MySQL syntax error #1064 - INSERT

From Dev

MySQL PDO Syntax error or access violation: 1064

From Dev

mysql query displaying #1064 - You have an error in your SQL syntax;

From Dev

1064 Sql syntax error in Mysql query

From Dev

#1064 SQL Syntax error

From Dev

mysql syntax error 1064 on create procedure

From Dev

MySQL said: Documentation (#1064) - You have an error in your SQL syntax;

From Dev

PHP MYSQL Syntax error or access violation: 1064

From Dev

MySQL Syntax error SQL Error [1064] [42000]: You have an error in your SQL syntax

From Dev

MySQL 1064 syntax error when using statement

From Dev

MySQL syntax error 1064 for "SELECT * FROM System"