0

I have an HTML form with a standard textarea that is used to leave update notes in text format. Any data saved there is then passed to an SQL database via Ajax where I am basically passing the value of the textarea.

This all works fine but sometimes the saved text then contains symbols like the following where it seems this happens when someone uses certain characters like ‘ , “ or & in the entered text which then adds the following in the database (among the rest of the entered text):

â€à OR “

Is there a way I can prevent this from happening in jQuery, e.g. by using a replace before passing it to the db ? The form is only used by English speakers so no need to cover special characters from other languages but it should work at least with standard text input.

Many thanks for any help with this, Tim.

user2571510
  • 11,167
  • 39
  • 92
  • 138
  • 1
    There's a mis-match of charset encoding, both the Database and the script/documents (And all layers of development) must match - otherwise this occurs. Alter the Database Charset to use the same Charset as defined on your HTML Document (`UTF-8` Recommended) – MackieeE Mar 07 '14 at 16:36
  • Thanks, I have that on my form - how would I check / set this in SQL (version 2008) ? – user2571510 Mar 07 '14 at 16:39
  • 1
    Check this [SO Q&A SQL Server Character Encoding](http://stackoverflow.com/a/5182334/292735), this may be part of the problem as, it seems `latin ISO 8859-1` is the default in SQL2008 (Apologies though, I've not used SQL2008 before) – MackieeE Mar 07 '14 at 16:45
  • Thanks a lot, I guess this might be the reason. Is there a way I can change this in the database. If I would change it in the header of my page would it then still be able to handle characters like ', " or & ? – user2571510 Mar 07 '14 at 17:40
  • for common characters such as those, I do believe so! Although I'm not sure about how to change the Column/Table to UTF-8, maybe upon creating the table itself you're able to define that. – MackieeE Mar 07 '14 at 18:35
  • Thanks. I checked on this and the issues doesn't seem to be with the database as I can enter any characters there manually. So I need something to do here either in the header of my file or then in my JS / Ajax function. – user2571510 Mar 08 '14 at 09:19
  • have you tested this on someone else's pc – Deryck Mar 08 '14 at 09:29
  • and `where I am basically passing the value of the textarea` is supposed to be what? in my experience the word "basically" actually means "I'm sure this isn't it because I'm convinced it's something else". This may not be your situation but you should post whatever code you have processing the posted data for submission and that of which is receiving it. – Deryck Mar 08 '14 at 09:33

0 Answers0