数据库保存奇怪的字符,无论我做什么

时间:2014-01-12 21:37:49

标签: php mysql database encoding

我搜索了高低,并使用了所有可能的解决方法,但无法使其工作。在管理员表单中,文章名称和文本,如果是俄语,它将被保存为一堆奇怪的字符。

我设置了html <meta>标签,PHP标头也设置为UTF8,使用mysqli_set_charset('utf8', $db),在我的数据库中,文章标题和文章文本行设置为utf8_general_ci。

我的表格排序也设置为utf8_general_ci;我无法得到任何工作!

if(isset($_POST['articleName'])){
    mysqli_set_charset('utf8', $mysqli_connect);
    if (($_POST['articleName'] == null) || ($_POST['cat'] == null)) {
        $errorMsg = "Insert at least article name and choose category";
    }else{
        $articleName = preg_replace("/[\s_]/", "-", $_POST['articleName']);
        $articleText = nl2br(htmlentities($_POST['articleText'], ENT_QUOTES, 'UTF-8'));
        $catList = implode(',', $_POST['cat']);  //gets all checked boxes
        if ($_POST['videolink'] != ""){
            $videolink = str_replace("watch?v=", "embed/", $_POST['videolink']);
        }else{
            $videolink = "";
        }
        $sql = mysqli_query($mysqli_connect, "SELECT id FROM table WHERE title='$articleName'");
        $row_check = mysqli_num_rows($sql);
        if ($row_check > 0){
            $errorMsg = "This article name is already in the database!";
        }else{
            $ins = mysqli_query($mysqli_connect, "INSERT INTO table...");

我不知道我还能在这做什么,请帮忙!

0 个答案:

没有答案