0

I am creating a PHP form, which collects items for a dropdown list from WordPress MySQL database. The database locale is set to utf8mb4_unicode_520_ci and I tried to force this in the code, however, my dropdown list still does not display any Cyrillic characters. There is a similar question already and I tried implementing possible solutions into my code, however

<head>
  <link rel="stylesheet" type="text/css" href="form-style.css">
</head>

<meta charset="utf-8">

<form action="upload.php" method="post" enctype="multipart/form-data">
  <div>
    <label for="video_name">Название Видео:</label>
    <input type="text" id="video_name" name="video_name" required>
  </div>
  <div>
    <label for="course_name">Название Курса:</label>
    <select id="course_name" name="course_name" required>
        
      <?php
        header('Content-Type: text/html; charset=utf8mb4_general_ci');

        // Connect to the MySQL database
        mysqli_set_charset($conn, 'utf8mb4_general_ci');
        mysqli_query($conn, "SET collation_connection = 'utf8mb4_general_ci'");
        $conn = mysqli_connect("host", "user", "pass", "db");
        
        // Query to select all course names
        $query = "SELECT post_title FROM wpv1_posts WHERE post_type = 'courses'";
        $result = mysqli_query($conn, $query);
        // Loop through the result set and create options for the dropdown list
        while ($row = mysqli_fetch_assoc($result)) {
          echo "<option value='".$row['post_title']."'>".$row['post_title']."</option>";
        }
        mysqli_close($conn);
      ?>
      

      
    </select>
  </div>
  <div>
    <label for="video_file">Файл Видео:</label>
    <input type="file" id="video_file" name="video_file" accept="video/*" required>
  </div>
  <input type="submit" value="Upload Video">
</form>

The result in the dropdown at the moment is basically:

Dropdown options
?????? 12345678
?????? ???? ????? Text
Any English Text

I tried forcing the locale through mysqli_set_charset($conn, "utf8mb4_unicode_520_ci"); and mysqli_query($conn, "SET collation_connection = 'utf8mb4_unicode_520_ci'");, as well as doing the same with cp1251_general_cs. I have updated header for my PHP and added the charset to the general file.

ISMAGILOV
  • 13
  • 3

0 Answers0