Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:01:51+00:00 2026-06-09T05:01:51+00:00

I am quite new to utf-8 encoding and have used htmlentities() ever since, but

  • 0

I am quite new to utf-8 encoding and have used htmlentities() ever since, but now want to change to have utf-8 in the database. I thought this might come in very handy, since as the website I am programming is German, I am using lots of umlauts.

However, it occurs to me I have a problem that I can’t explain. In the html head, I say

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

For testing, if I type a plain “ö” and hardcode it in html, it is displayed fine.

Now here comes the queer thing: In my database, I have an entry “Köln” – in the database it looks exactly like this. However, when I get the string from the table with php and echo it out, it is echoed out as “K�ln”.

On the other hand, if I type in umlauts and send that to the table with ajax, “Köln” – the string that I typed in – becomes “Köln” in the database.

I use the following code for that:

//Change city
$('#newcitybutton').click(function(){
//Get id and city
var id=encodeURIComponent($('#id').html()); //This does not seem to be the problem - if I leave that out, I still does the same thing
var city=$('#newcity').val();

//Call script to change city
$.ajax({
    type: 'POST',
    url: 'action/changecity.php',
    data: 'id='+id+'&city='+city+'&kind='+kind,
    success: function(feedback){
        var json=$.parseJSON(feedback);
        if(json.success=='false'){
            $('#newcityfeedback').css('color','red').html(json.message).hide().fadeIn(200);
        }else if(json.success=='true'){
            $('#newcity').hide();
            $('#newcitybutton').hide();
            $('#'+kind+'city').html(decodeURIComponent(city));
            $('#newcityfeedback').css('color','green').html(json.message).hide().fadeIn(200).delay(2000).fadeOut(200);
        }
    }
});
});

Changecity.php:

//Save in vars
$id=$_POST['id'];
$city=$_POST['city'];
$kind=$_POST['kind'];

//Update city
$query="UPDATE ".$kind."s SET city='$city' WHERE id=$id";
mysql_query($query);

I figured that when I use $city=utf8_decode($city); before putting in in the database, it is saved there correctly. But then I need to use utf8_encode to display it correctly on the page.

What am I doing wrong here? I just can’t figure out whether the mistake comes from my code, or the database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:01:53+00:00Added an answer on June 9, 2026 at 5:01 am

    Try using the PHP function mysql_set_charset() with “UTF8” as parameter.

    http://php.net/manual/en/function.mysql-set-charset.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: Quite new to DI and Ninject but would love to master it so
Still quite new to Haskell.. I want to read the contents of a file,
I am quite new to mongoid and rails. So I have some troubles to
Quite new to functional languages, but I'm maintaining someone else's code with a lot
I'm new to Python (I have been programming in Java for multiple years now
I have the following shape XML: <?xml version=1.0 encoding=utf-8?> <shape xmlns:a=http://schemas.android.com/apk/res/android a:shape=ring a:innerRadiusRatio=3 a:thicknessRatio=8
I have a list of UTF-8 strings that I want to sort using Enumerable.OrderBy
Hi I have the following xml <?xml version=1.0 encoding=UTF-8?> <root> <item> <name>john</name> <year>2010</year> </item>
I have the following sample XML: <?xml version=1.0 encoding=utf-8 ?> <queryableData> <table displayName=Shipments dbName=Quotes>
I'm quite new to programing and have a problem. I have been using touchxml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.