1

I have a checkbox, which changes the content of a table when it's clicked.

For some reason, my UTF-8 is no longer working after I have submitted the form with ajax.

Ajax:

function showUser() {
if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
} else {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        document.getElementById("table").innerHTML = xmlhttp.responseText;
    }
}
xmlhttp.open("GET","getuser.php?customer="+variable);
xmlhttp.send();
}

and getuser.php:

    $customer = intval($_GET['customer']);

   $connection = mysqli_connect('localhost','root','*********','name');
   if (!$connection) {
    die("Could not connect: " . mysqli_error($connection));
    }

    if($customer == 1) {
    $searchType= 1;
    } else {
    $searchType= 0;
    }

    $sql="SELECT * FROM table WHERE type= $searchType";

    $result = mysqli_query($connection,$sql);

After this I echo a table with content got from the database. In my database there is some customers that has some special characters in their name. Instead of showing them like usual, it only shows ? in place of those special characters.

Any help? (sry for my bad english)

colzu
  • 131
  • 1
  • 8
  • Is it specifically `?` or actually `�` ? – Musa Feb 02 '15 at 13:21
  • A [nice article about utf-8 encoding in php and mysql](http://www.toptal.com/php/a-utf-8-primer-for-php-and-mysql). – skobaljic Feb 02 '15 at 13:23
  • @Musa it's �, sorry for not mentioning that, I didn't know the charcode for that – colzu Feb 02 '15 at 13:24
  • Keep all files in UTF8 (no bom!), set page headers with UTF 8 char set, keep database in UTF8 and database connections in UTF8 and it should work. – MilanG Feb 02 '15 at 13:27
  • @skobaljic I have basically tried everything on that page, in my php.ini My default charset is utf-8, inside my tag there is set to UTF-8, I have encoded it manually with Notepad++, I have tried php header content-type. It still doesen't work. – colzu Feb 02 '15 at 13:28
  • 2
    Try setting the character set just before you query then. http://php.net/manual/en/mysqli.set-charset.php - 9 times out of 10, is the fix. – Funk Forty Niner Feb 02 '15 at 13:31
  • You're welcome. I decided to close the question as a duplicate, since the information I've given you *for the fix* is inside that page, *cheers*. – Funk Forty Niner Feb 02 '15 at 13:36

0 Answers0