Solved

encoding problems saving in mysql table

Posted on 2009-05-06
2
729 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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…

759 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