Search code examples
phpmysqlmysql-error-1064

MySQL Error in PHP but not through CLI


Update: I found the problem, I output the sql statement to a file instead of on the screen and noticed an extra hidden char towards the end of the sql statement. Once I removed that the query worked fine. Cutting and pasting the statement from the web was omitting that. Thanks for the help. Fixed.

I receive a 1064 error from mysql with the following query:

    update `table` set `id` = "152614",
`Field2` = "151",
`Field3` = "11",
`Field4` = "1587",
`Field5` = "Elevator",
`Field6` = "",
`Field7` = "",
`Field8` = "",
`Field9` = "",
`Field10` = "",
`Field11` = "",
`Field12` = "0",
`Field13` = "0",
`Field14` = "0",
`Field15` = "0",
`Field16` = "0",
`Field17` = "0",
`Field18` = "0",
`Field19` = "0",
`Field20` = "0",
`Field21` = "0",
`Field22` = "0",
`Field23` = "0",
`Field24` = "0",
`Field25` = "0",
`Field26` = "0",
`Field27` = "0",
`Field28` = "0",
`Field29` = "0",
`Field30` = "0",
`Field31` = "0",
`Field32` = "0",
`Field33` = "0",
`Field34` = "0",
`Field35` = "0",
`Field36` = "1065353216",
`Field37` = "0",
`Field38` = "0",
`Field39` = "0",
`Field40` = "0",
`Field41` = "0",
`Field42` = "0",
`Field43` = "0" where id ="152614"

MySQL error 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 '' at line 43

Line 43 is the last line.

If I paste it into the mysql CLI it works fine:

Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0

At this point I'm at a loss, any ideas? Thanks.

MySQL Version: 5.1.52 PHP Version: 5.3.3

It's fairly deep in my script, but the part that produces the error is:

$result  = mysql_query( $sql );
if (mysql_errno()) { 
echo  "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing <br>\n$sql\n<br>";

If I output $sql, it's identical to the paste for the query above ( above is from the error line ).


Solution

  • I found the problem, I output the sql statement to a file instead of on the screen and noticed an extra hidden char towards the end of the sql statement. Once I removed that the query worked fine. Cutting and pasting the statement from the web was omitting that. Thanks for the help. Fixed.