JBL
JBL

Reputation: 247

PHP Chinese Characters Can't Insert To Mysql

I am using GET to pass parameters, succesful save data to mysql if the data is in english, but nothing insert if the data is in chinese.

I have detected the data encoding is utf-8, found out that using my macbook it works fine, but not working on ie. Strange, any idea what's wrong with it?

For example

query("insert into Info  values ('".$email."','".$_GET['name']."')");

This not successful if $name is chinese. I have tried echo $_GET['name'] and display normally, howerver the data can't inserted to databse is blank.

query("insert into Info  values ('".$email."','香港')");

This method successful insert data to database

Upvotes: 1

Views: 1792

Answers (1)

Michael Robinson
Michael Robinson

Reputation: 29508

Firstly, you really should use POST for these operations.

Check to ensure that the column you are inserting into has the correct encoding - perhaps export the table structure for us to see if you're not sure.

As Daan said, you could try

query('SET NAMES UTF8'); 

Before your insert query.

Upvotes: 2

Related Questions