0

Until recently the following code worked correctly.

for player in away_starters_names:
 on = 0
 this_player = player[0]
 if this_player in event:
 player_id = away_team_dict[this_player]
 player_id = int(player_id[0])
 team = 0
 team_id = away_id
 cur.execute("""INSERT INTO football.match_subs(player, time, added, game_id, home, on, team_id) VALUES (%s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE game_id = game_id""", (player_id, time, added, game_id, team, on, team_id))
 db.commit()

It now gives this error:

 Traceback (most recent call last):
 File "Z:\Coding\bbc\find_teams.py", line 508, in <module>
 cur.execute("""INSERT INTO football.match_subs(player, time, added, game_id, home, on, team_id) VALUES (%s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE game_id = game_id""", (player_id, time, added, game_id, team, on, team_id))
 File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 202, in execute
 self.errorhandler(self, exc, value)
 File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
 raise errorclass, errorvalue
ProgrammingError: (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 'on, team_id) VALUES (299191, 89.33, 0, 21570967, 0, 0, 2) ON DUPLICATE KEY UPDAT' at line 1")

What is wrong?

Nathaniel Ford
21.3k20 gold badges98 silver badges112 bronze badges
asked Mar 4, 2013 at 22:50
2
  • okay looking at the way this is highlighted on here (not on idle) it is blatently going to be using 'on' as a column name.. Commented Mar 4, 2013 at 22:55
  • always escape your inputs. Always. Commented Mar 4, 2013 at 22:56

1 Answer 1

2

Use backticks around your field names. ON is a reserved word in MySQL

answered Mar 4, 2013 at 22:59
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.