2

I am trying to insert simplified chinese into my mysql table using UTF8_unicode_ci. Everything including the connection is configured to use UTF8.

When I try an insert these characters into the database table using a traditional HTML form post using PHP, I get the MySQL invalid string value error message. The strange thing is that if I use Jquery to post the information to another PHP page to store in the database, I get no error and the data goes in fine.

I am wondering what the differences are. Can anyone shed some light on this issue?

It happens for all data as far as i know. I connect to mysql using: $this->link = mysql_connect(cj_config::CJ_DB_HOST, cj_config::CJ_DB_USERNAME, cj_config::CJ_DB_PASSWORD); and then select the appropriate database using mysql_select_db.

The table collation is utf8_unicode_ci, and the column is also set to utf8_unicode_ci. The database collation and connection are all set to Utf8 also.

The error i am getting when sending the html form post is :

Error: Incorrect string value: '\x9A' for column 'company_name' at row 1.

I don't get this error when posting the same chinese character via jquery post and mysql does not complain.

The source of this jquery post is below and looks properly utf8 encoded:

customer=7&task_title=%E5%95%8A&task_notes=%E5%95%8A&datetime=&method=addtaskg&smallview=true
cwiggo
  • 2,541
  • 9
  • 44
  • 87
mark377
  • 91
  • 8
  • Does it happen on some data or all data there? Could you also share the code on how you set up the connection string and table? Also some sample data would help. – ydoow Oct 20 '15 at 00:46
  • I have been using the character 啊 which apparently gets represented as \x9A (with PHP) and %E5%95%8A when doing a jquery post. – mark377 Oct 21 '15 at 10:41
  • Switch to UTF-8 **everywhere**, including HTML. AJAX works fine because UTF-8 is mandatory there and jQuery takes care of the details. – Álvaro González Oct 21 '15 at 10:50

0 Answers0