1

I am working on a project where I am storing data in a foreign language in MYSQL. While in the database, its alright since I have set the collation to 'utf8-general-ci'. I can view it without any problem. But when I try to retrieve the data into a php document, it doesn't work. My Code is:

  <?php

    $servername = "localhost";
$username = "root";
$password = "";
$dbname = "31stknowledge";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


mysql_set_charset('utf8');
$sql = "SELECT * FROM course";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $Course = $row["Course"];
        $Duration = $row["Duration"];
        $Type = $row["Type"];
        $Description = $row["Description"];
        $Image = $row["Image"];
        header("Content-type: text/html; charset=utf-8");
         echo "<div class='col-lg-6 portfolio-item'>";
          echo "<div class='card h-100'>";
            echo "<a href='#'><img class='card-img-top' src='$Image' alt=''></a>";
            echo "<div class='card-body'>";
              echo "<h4 class='card-title'>";
                echo "<a href='#'>$Course</a>";
              echo "</h4>";
              echo "<p class='card-text'>$Description</p><br>";
              echo "<p class='card-text'>$Type</p><br>";
              echo "<p class='card-text'>$Duration</p><br>";
            echo "</div>";
          echo "</div>";
        echo "</div>";

    }
} else {
    echo "0 results";
}
$conn->close();
?>

Can anyone point out my mistake and guide me to the right direction? Thanks in Advance.

0 Answers0