0

I have a select box in PHP that retrieves data from MySQL, but the data that have accents are shown with special characters. Before I added the select box all was good. How can I fix it?

Here is my code:

<html>
    <head>
    <meta charset="utf-8">
        <!-- importer le fichier de style -->
        <link rel="stylesheet" href="Style/style1.css" media="screen" type="text/css" />
        <title>Ajouter un Scanner </title>
        <body>
        <div id="container">
            <!-- zone de connexion -->

            <form   action ="insert.php" method="post">
                <h1>Ajout d'un Scanner</h1>
                <label><b>Catégorie</b></label><br>
                <?php
                $mysqli = new mysqli("localhost", "root", "", "mapbdd") or die($this->mysqli->error);
                $query = $mysqli->query("SELECT icone_categorie FROM markers_icone");
                //$result = mysqli_query($query);
                ?>
                <select name="select_categorie" id='select_categorie'type="List" >
                  <option value="-1"></option>
                <?php
                while($row =  $query->fetch_array(MYSQLI_ASSOC)){
                  echo "<option>{$row['icone_categorie']}</option>";
                }
                ?>
                </select>
                <br><br>
                <label><b>Ville</b></label>
                <input type="text" placeholder="Entrer la ville" name="fville" required>

                <label><b>Longitude</b></label>
                <input type="text" placeholder="Entrer la longitude" name="flong" required>

                <label><b>Latitude</b></label>
                <input type="text" placeholder="Entrer la latitude" name="flat" required>

                <label><b>Description</b></label>
                <input type="text" placeholder="Description" name="fdesc" required>

                <input type="submit" id='submit' value='Insérer' >

            </form>
        </div>


    </body>
    </head>

Thank you

1 Answers1

0

Try to insert this

$mysqli->set_charset("utf8");

after this line:

$mysqli = new mysqli("localhost", "root", "", "mapbdd") or die($this->mysqli->error);

(to set the charset for the mysqli connection)

Johannes
  • 64,305
  • 18
  • 73
  • 130
  • I have the same problem here with PDO , what can I put ? –  May 02 '18 at 10:37
  • $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("SELECT marker_categorie, marker_ville, marker_longitude, marker_latitude,marker_text FROM markers"); $stmt->execute(); // set the resulting array to associative $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { echo $v; –  May 02 '18 at 10:39