Forum Moderators: coopster

Message Too Old, No Replies

Storing special characters in MySQL

What field type should I use?

         

cochranrg

4:18 am on Apr 16, 2006 (gmt 0)

10+ Year Member



I am inputting a large text field into MySQL. Keep getting syntax errors and have found that these are being caused by special characters such as quote '. Other characters cause this problem as well.

Is there a field type or something I can do to allow all of these characters without erroring out? I have tried BLOB and TEXT and VARCHAR. Text string may be very large.

Thanks in advance,
RC

dreamcatcher

6:28 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi cochranrg,

There are a few ways you can sort this problem. Try using addslashes() [uk.php.net] before your database insertion, or mysql_real_escape_string() [uk.php.net].

Alternatively you can convert apostrophes and other problematic characters to character entities before insertion.

dc