如何在网页上显示存储在mysql数据库中的孟加拉语数据

svgewumm  于 2021-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(479)

我正在做一个cms,必须在这个cms提交孟加拉语数据,并显示孟加拉语数据,但孟加拉语数据是看不到正确的,但点击提交按钮,看到孟加拉语正确。这个问题将如何解决?
单击提交按钮之前:

单击提交按钮后:

我的代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
    </head>
    <body>
        <?php
                $servername = "localhost";
                $username = "root";
                $password = "";
                $db ="bangla";
                $con1 = new mysqli($servername, $username, $password);
                $db_create = "CREATE DATABASE IF NOT EXISTS bangla CHARACTER SET utf8 COLLATE utf8_general_ci";

                if ($con1->query($db_create) === TRUE) {
                    echo "Database 'bangla' created successfully<br>";
                } 
                else {
                      echo "Error creating database: " . $con1->error;
                }
                $con2 = new mysqli($servername, $username, $password, $db);
                $table_create = "CREATE TABLE IF NOT EXISTS user (
                    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                    name VARCHAR(30) NOT NULL,
                    father VARCHAR(30) NOT NULL,
                    village VARCHAR(30)
                )ENGINE=MyISAM DEFAULT CHARSET=utf8";

                if ($con2->query($table_create) === TRUE) {
                    echo "Table 'user' created successfully<br><br>";
                } 
                else {
                      echo "Error creating database: " . $con2->error;
                }

                if (isset($_POST['submit'])) {
                    mysqli_query($con2, "SET CHARACTER SET utf8");
                    mysqli_query($con2, "SET SESSION collation collation='utf8_general_ci'");
                    $name = $_POST["name"];
                    $father = $_POST["father"];
                    $village = $_POST["village"];
                    $query = "INSERT INTO user (id, name, father, village) 
                    VALUES (NULL, '$name', '$father', '$village')";
                    $run = mysqli_query($con2, $query);
                    if ($run) {echo "User created successfully. ";} 
                    else {echo "User created fail.";}
                }
            ?>  
            <form  method ="post" accept-charset="utf-8">
                <input type="text" name="name" placeholder="Name">
                <input type="text" name="father" placeholder="father name">
                <input type="text" name="village" placeholder="village name">
                <input type="submit" value="submit" name="submit">
              </form>
                <?php
                $sql = "SELECT name, father, village FROM user";
                $result = $con2->query($sql);
                if ($result->num_rows > 0) {
                    while($row = $result->fetch_assoc()) {
                        echo "Name:" . $row["name"]. " <br>Father name: " . $row["father"]."<br>Village name:". $row["village"]."<br><br>";
                    }
                } else {
                    echo "0 results";
                }
        ?>
    </body>
</html>
egmofgnx

egmofgnx1#

写在“头”标签上

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
kse8i1jr

kse8i1jr2#

我已经通过使用
$con->set\u字符集(“utf8”);
我的配置文件:

<?php

// Creating a database connection

$con = mysqli_connect("localhost", "root", "root", "bibahabd_datacollect");
if (!$con) {

    die("Database connection failed: " . mysqli_connect_error());
}
$con->set_charset("utf8");

// Selecting a database

$db = mysqli_select_db($con, "bibahabd_datacollect");
if (!$db) {
    die("Database selection failed: " . mysqli_connect_error());
}

?>

相关问题