Solved

encoding problems saving in mysql table

Posted on 2009-05-06
2
713 Views
Last Modified: 2013-12-12
I've had a bad night sleep over this... Can't figure out where it goes wrong.

in a form, the user is entering a field with e.g. "åäö" ,
a (AJAX) javascript is submitting it to a php file using POST submition and using encodeURIComponent
so the characters enter the php page like "%C3%A5%C3%A4%C3%B6" so far so good.
to insert this in the mysql database the php script translates this back with urldecode() (also tried rawurldecode) as far as i can see, the query send to the database contains the carachters "åäö" again. This is also as expected.

Now for the fun part;
when ik look in phpmyadmin what data is saved in the table i see:åäö as a value. NOT AS EXPECTED and certainly not wanted ;) if i display the table values in the front-end HTML page it also displays as: åäö.
If i on the other hand copy my query and paste it into phpmyadmin  and execute it, it all works out well, the åäö are saved properly. The AJAX javascript getting the values from the database in the backend messes up then but is step 2.

As far as i can see my database, tables and fields are encoded "latin1_swedish_ci"

now, where does this go wrong?
SNAG-0009.jpg
SNAG-0010.jpg
0
Comment
Question by:half-a-nerd
2 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24322851
Hi,

check your apache.conf  file for  AddDefaultCharset  variable.

If there is no , add AddDefaultCharset UTF-8.


And try again .hope this will help you.

Regards
0
 
LVL 3

Accepted Solution

by:
HMoellendorf earned 500 total points
ID: 24343296
Hello half-a-nerd,

thank you for posting at EE. It seems to be a charset problem. It is more better to convert the charset of the tables to utf8. Further, it could help to set the client_encoding after connecting to mySQL:

http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html

Then it should work.

If you habe further questions let us know.

Kind regards,
Henning
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now