2

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 ).

7
  • 1
    can you please paste you php code? Commented Dec 7, 2010 at 2:46
  • Strange. Are you sure that is the exact value that $sql is? how are you building the $sql query? Commented Dec 7, 2010 at 2:55
  • I tried to output $sql right before the $result line, and pasting that into the CLI and received the identical result ( Query OK..). I'm creating the $sql by reading a binary file and then: $sql .= ''.$field['name'].' = "'.mysql_real_escape_string($data).'",'; Commented Dec 7, 2010 at 3:07
  • try using single quotes in the query. Commented Dec 7, 2010 at 3:10
  • I tried switching all the double quotes to singles, same error. Commented Dec 7, 2010 at 3:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.