php Error description: Incorrect string value: '\xF4t l'\xE9…' on insert

前端 未结 2 1977
孤街浪徒
孤街浪徒 2021-01-13 07:08

I am inserting data from a UTF8-general-ci table to another UTF8-general-ci table. These are articles. About 20 or 30 will not insert due to random use of French titles or p

相关标签:
2条回答
  • 2021-01-13 07:11

    Try this with utf8_encode();

            $sql = "INSERT INTO table (col1)
            VALUES ('".utf8_encode($input_variable)."')";
    
            if ($conn->query($sql) === TRUE) 
            {
                echo "Inserted!";
            } else {
                echo "Error: " . $sql . "<br>" . $conn->error;
            }
    
    0 讨论(0)
  • 2021-01-13 07:34

    The bytes you've quoted in your question (F4 and E9) aren't valid in UTF-8 data. Some or all of your data is probably actually ISO-8859-1 — you'll need to convert it to UTF-8 using mb_convert_encoding() or iconv().

    0 讨论(0)
提交回复
热议问题