Solved

encoding problems saving in mysql table

Posted on 2009-05-06
2
709 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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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 …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

743 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

15 Experts available now in Live!

Get 1:1 Help Now