I am currently building part of a website and one the features is having a select element that is populated with data from my database. I have already coded this in order to work but now on the webpage some caracters get converted to symbols. For example letters like this ç, ã, á, à, and so on. I tried to check the collation of the database and right now is utf8mb4_unicode_ci. Can somebody help me? Here's the code I have on the webpage:
PHP:
<?php
// Database connection settings
$host = 'host';
$username = 'user';
$password = 'password';
$database = 'database_name';
// Connect to the database
$conn = mysqli_connect($host, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Query the database to retrieve data from a specific column
$sql = "SELECT Nome_Curso FROM listed_courses";
$result = mysqli_query($conn, $sql);
// Loop through the result set and create an option element for each item
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['Nome_Curso'] . "'>" . $row['Nome_Curso'] . "</option>";
}
// Close the database connection
mysqli_close($conn);
?>
JS:
// Get the select element
const select = document.getElementById('select-courses');
// Call the PHP script using AJAX and populate the select element with the result
fetch('/assets/php/getdata.php')
.then(response => response.text())
.then(data => select.innerHTML = data);
And then on html I simply have a select tag.
NOTE: I am using a mariadb database