PDA

View Full Version : Abbrievation problems :(


Y-STU-K
09-21-2002, 07:30 PM
Ok heres my problem

When i add some text to my database from a form which has an abbrievation in, it fails to run the add query correct. heres and example of what i mean

i'm, don't basically any word with a ' in. Is there a way to get text to save to the database with this character in, because mysql must be taking the ' as the end of the string.

Anyone have any ideas on how to solve my little problem

mordred
09-22-2002, 01:05 AM
In your SQL query, you have to escape "problematic" characters so that the SQL parser understands that they should not be read as a the end of a string value. Example:

UPDATE tableName SET field = 'don\\'t do that now'

See how that single quote inside the string is escaped by prepending it with the backslash?

If you work with PHP together with MySQL, you can (and should) make use of the very helpful function addslashes():

http://www.php.net/manual/en/function.addslashes.php

Y-STU-K
09-22-2002, 11:03 AM
Ah right excellent, yeah thats just the thing :)

I thought of a solution after i made this post but its a bit cumbersome i seached a string got instanced of the quote and then re-wrote them escaped and then the displaying them i used the explode() function

didn't quite work right and took ages :E