0

I am trying to do an INSERT into my table called 'outfield' which consists of the following fields: outfieldplayerID (auto-increment and PK), Surname, Forename, Team, Games Played, Games Started, Minutes Played, Goals, Assists, Shots, Shots on goal, Yellow cards, Red cards

My code is as follows:

import mysql.connector

conn = mysql.connector.connect(user='root',password ="password5",host='localhost',database='performance')
query = "INSERT INTO outfield ('Surname', 'Forename', 'Team', 'Games Played', 'Games Started', 'Minutes Played', 'Goals', 'Assists', 'Shots', 'Shots on goal', 'Yellow cards', 'Red cards') values('a','b','c','1','1','1','1','1','1','1','1','1')"

cursor = conn.cursor()
cursor.execute(query)
conn.commit()
rows = cursor.fetchall()
cursor.close()
conn.close()

I am getting a syntax error in the INSERT line. Where am I going wrong?

Shadow
  • 33,525
  • 10
  • 51
  • 64
hoops9682
  • 35
  • 5

1 Answers1

0

Use backticks `` instead of single quote '' in column names:

insert into outfield (`Surname`, `Forename`, `Team`, `Games Played`, `Games Started`, `Minutes Played`, `Goals`, `Assists`, `Shots`, `Shots on goal`, `Yellow cards`, `Red cards`)
values ('a', 'b', 'c', '1', '1', '1', '1', '1', '1', '1', '1', '1')

Also, it's better to define the identifiers in such a way that you don't need to use the backticks at all.

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76