# Python MySQL error

**URL:** <https://community.unix.com/t/python-mysql-error/290526>\
**Category:** Programming\
**Created:** [June 27, 2011, 11:16am UTC](https://community.unix.com/t/python-mysql-error/290526 "2011-06-27T11:16:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmd006](https://community.unix.com/user_avatar/community.unix.com/pmd006/32/7125_2.png) [@pmd006](https://community.unix.com/u/pmd006)\
**Post date:** [June 27, 2011, 11:16am UTC](https://community.unix.com/t/python-mysql-error/290526/1 "2011-06-27T11:16:58Z")

</div>

Hey all,  
I'm trying to enter some data into a database and I keep getting this error:

```nohighlight
Traceback (most recent call last):
  File "./ais_file_parser.py", line 77, in <module>
    cursor.execute(sql)
  File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, 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 syntax to use near '('366978440', '46.500150', '-84.338107', CURRENT_TIMESTAMP)' at line 3")

```

The mysql command that I'm running is this:

```nohighlight
#add the location entry to the database
sql = "INSERT INTO `ship_location`\n \
VALUES (`userid`, `latitude`, `longitude`, `date_time`) \n \
('%d', '%f', '%f', CURRENT_TIMESTAMP);" % (msg.userid, DMToDec(lat_dd, lat_min), DMToDec(long_ddd, long_min))

```

I set up the database so the date\_time field has a default of the CURRENT\_TIMESTAMP. From the error message, you can see that the userid is being sent an integer, and the latitude and longitude are both getting floats and when I set up their fields in MySQL I set them as FLOAT(10,6). So it might then be a problem with the sql syntax, but I can't see it. I've tried tried multiple ways of doing it, so I'm kind of at my wits end with it.

Any help would be appreciated.

[edit] Also thought I should add that I tried entering 366978440, 46.500150, -84.338107 into the user\_id, longitude and latitude fields respectfully, and it works.

---

<div class="post-metadata">

**Author:** ![pmd006](https://community.unix.com/user_avatar/community.unix.com/pmd006/32/7125_2.png) [@pmd006](https://community.unix.com/u/pmd006)\
**Post date:** [June 28, 2011, 10:27pm UTC](https://community.unix.com/t/python-mysql-error/290526/2 "2011-06-28T22:27:21Z")

</div>

Figured out my problem, I had "VALUES" in the wrong place. Needed to go after the names of the columns.
