Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

encoding problems saving in mysql table

Posted on 2009-05-06
2
Medium Priority
?
744 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 1500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

877 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