简体   繁体   中英

How to insert chinese character into database

i am trying to add Chinese character in my database. I am adding this 黔西南布依族苗族自治州 and getting this 黔西å—布ä¾æ any help?

header('Content-Type: text/html; charset=utf-16');

header('Content-Type: text/html; charset=utf-8');  

if(isset($_POST['totalprice'])){

        $totalprice=$_POST['totalprice'];
        $price=$_POST['price'];
        $qty=$_POST['count'];
        $color=$_POST['color'];
        $name=$_POST['name'];
        $phone=$_POST['phone'];
        $address=$_POST['address'];
        $province=$_POST['province'];
        $city=$_POST['city'];
        $region=$_POST['region'];
        $payment=$_POST['payment'];
        $message=$_POST['message'];
        $model=$_POST['model'];
        $commodity=$_POST['commodity'];
        $totalprice=$_POST['totalprice'];
        $name=$_POST['name'];
        $description='';

        $sql="INSERT INTO `orderItems`( `commodity`, `model`, `color`, `qty`, `total`) VALUES ('$commodity','".$model."','".$color."','".$qty."','".$totalprice."')";
           $db->query($sql);
}

Please use utf8mb4 when you insert to table

set username utf8mb4; INSERT INTO table_name (aaa,VAL);

you can just do it by alter table field from phpmyadmin and set type to utf8mb4 .

mysqli_query("SET character_set_results=utf8mb4", $db);

Sometimes MySQL's utf8 does not support.This is because of a small number of Chinese characters that require 4-byte UTF8 characters.So utf8mb4 used.

change that column's charset/collection from Default charset to utf8

then you can insert anything in that column

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM