PDA

View Full Version : Data from table to table getting error 1064


sideshore
06-12-2003, 11:04 AM
I getting this error code 1064 when inserting some data into a table.

The funny thing is that the data that I am inserting, comes directly out of another table.

I get the error message when I use quotes in my message.

example:
test 'bug' test

The total error message is:
1064: You have an error in your SQL syntax near 'bug' test'' at line 1

does anyone have any idea how to solve this?

Many thanks
JW

raf
06-12-2003, 12:23 PM
Welcome here.

SQL statement should not have quotes in the values (like you found out)
Sollution depends on the scripting language you use. For ASP, you need to replace the single quotes by two single quotes --> see sticky on top of the ASP forum.
http://www.codingforums.com/showthread.php?s=&threadid=9843
For PHP, you best use addslashes(). More info here http://be.php.net/manual/en/function.addslashes.php

sideshore
06-12-2003, 02:20 PM
Thanks for your reply!
It worked!:thumbsup:

But why isn't it going wrong when I'm putting the variable (the message) in the first table? Then there are also quotes present.

raf
06-12-2003, 02:43 PM
How did you insert them in that table? It probably wount be by using embeded sql in ASP or PHP, or you used a replace or addslashes() ... + if you look in your db, you will see that the quotes are still there -->the RDBM will magically transform the value back to "test 'bug' test".
So if you select them and insert them again, you'll select "test 'bug' test" but need to insert "test ''bug'' test" or "test \'bug\' test" but the resulting value that is saved will be "test 'bug' test".

sideshore
06-12-2003, 03:15 PM
Thanks :thumbsup:

I used php to insert them in the table. And used htmlentities to insert them into the first table. So that's probably why it's working for the first table and wasn't working for the second.

Many Thanks
JW