0

I want to save some user input to my database and most of the time this works just fine. However, when the user wants to save the character à my script returns the following error:

Incorrect string value: '\xC3

I've tried various other characters, such as éúáíó-öđęĨłƕǣʭβۺ-èüòïçÇÈò-èòìù-ÒÌÙÈ À which all work fine. Even the capitalized À works fine!

I've googled and, even though I'm pretty sure my character set isn't the problem (all other characters work fine), I made sure everything is UTF-8. With everything I mean: the user input form, the documents, the database connection, the default character sets in my database and the actual columns from the tables in my database.

edit (added php code)

 $mysqli = new mysqli($db_server, $db_username, $db_password, $db_database);
 $mysqli->set_charset("utf8");
 $mysqli->query('SET NAMES utf8');

 if ($addToQueue = $mysqli->prepare("INSERT INTO table (html) VALUES (?)")) {
        $addToQueue->bind_param('s', $html;);

        $html = preg_replace('/\s/u', '', 'àĠӠ');

        $addToQueue->execute();
 }

What is going on here / am I doing wrong?

Any help is greatly appreciated!

David Janssen
  • 161
  • 1
  • 6
  • And the php code that throws the error is? – developerwjk Jun 17 '14 at 14:57
  • Please provide your code. So that we can able to find possible ways. – Gunaseelan Jun 17 '14 at 14:59
  • http://stackoverflow.com/questions/1168036/how-to-fix-incorrect-string-value-errors Check this question – Gunaseelan Jun 17 '14 at 15:07
  • Check whether the string value '\xC3 belongs to 'utf-8' – Gunaseelan Jun 17 '14 at 15:28
  • 1
    The UTF-8 sequence for `à` is `C3 A0`, so it sounds like the `A0` part gets stripped away somehow and only the `C3` part remains, which is an incorrect UTF-8 sequence... Does some part of the program think that `A0` is a space, which needs to be removed or something? What happens if you try to save another character that contains `A0` in its sequence, such as `Ġ` or `Ӡ`? – Mr Lister Jun 17 '14 at 16:49
  • Is the source code file saved as UTF-8...? – deceze Jun 18 '14 at 06:11
  • @MrLister got me on the right track. 'A0' gets stripped off $html for some reason. This happens because I'm using preg_replace and when I add a `u-flag` everything works fine: `$html = preg_replace("/\s/u", "", $html);` – David Janssen Jun 18 '14 at 06:23
  • Ah, OK then. I could make a nice answer out of that, if the question were to be reopened. Now that you added the code in question, it's no longer off-topic! – Mr Lister Jun 18 '14 at 07:17
  • Maybe @deceze can re-open the question? – David Janssen Jun 20 '14 at 09:11

0 Answers0