-1

I have this php code an my problem is with utf8 charset. When i retrieve data from mysql the utf8 is not working. Any ideas about what is wrong? Mysql collation is utf8_general_ci. But my php still shows me lots of question marks (?) instead of greek. Below i have 3 screenshots of my search results, my sqlserver and my database. Any help would be great. Thanks.

http://prntscr.com/cqj1ei http://prntscr.com/cqj25d

<?php

if(isset($_POST['search']))
{
    $valueToSearch = $_POST['valueToSearch'];
    $sql = "SELECT * FROM `works` WHERE CONCAT(`Onomateponumo`, `Odos`, `Arithmos`, `Perioxi`, `Hmerominia`, `Ora`, `Ergasia`, `Amoivi`, `Ypallilos`, `Tilefono`, `Alles_plirofories`) LIKE '%".$valueToSearch."%'";
    $search_result = filterTable($sql);
}
else {
    $sql = "SELECT * FROM `works`";
    $search_result = filterTable($sql);
}

function filterTable($sql)
{
    $connect = mysqli_connect("localhost", "root", "", "works1");
    $filter_Result = mysqli_query($connect, $sql);
    mysqli_set_charset($connect, "utf8");
    return $filter_Result;
}

?>
<?php header('Content-Type: text/html; charset=utf-8');?>
<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Προγραμμα Αναζητησης</title>
        <style>
            table,tr,th,td
            {
                border: 1px solid black;
            }
        </style>
    </head>
    <body>

        <form action="fetch.php" method="post">
            <input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
            <input type="submit" name="search" value="Filter"><br><br>

            <table>
                <tr>
                    <th>Όνοματεπώνυμο</th>
                    <th>Διεύθυνση</th>
                    <th>Τηλέφωνο</th>
                    <th>Περιοχή</th>
                    <th>Ημερομηνία</th>
                    <th>Εργασία</th>
                    <th>Αμοιβή</th>
                    <th>Υπάλληλος</th>
                    <th>Τηλέφωνο</th>
                    <th>Πληροφορίες</th>
                </tr>
                <?php while($row = mysqli_fetch_array($search_result)):?>
                <tr>
                    <td><?php echo $row['Onomateponumo'];?></td>
                    <td><?php echo $row['Odos'];?></td>
                    <td><?php echo $row['Arithmos'];?></td>
                    <td><?php echo $row['Perioxi'];?></td>
                    <td><?php echo $row['Hmerominia'];?></td>
                    <td><?php echo $row['Ergasia'];?></td>
                    <td><?php echo $row['Amoivi'];?></td>
                    <td><?php echo $row['Ypallilos'];?></td>
                    <td><?php echo $row['Tilefono'];?></td>
                    <td><?php echo $row['Alles_plirofories'];?></td>
                </tr>

                <?php endwhile;?>
            </table>


        </form>


    </body>
 </html>

1 Answers1

0

Set all mysql encodings

mysqli_query($connect, "SET NAMES 'utf8'");

Check PHP internal character encoding

echo mb_internal_encoding();

If not UTF-8

mb_internal_encoding("UTF-8");
MichaEL
  • 84
  • 4
  • @ChristosKyritsis: did u tried? htmlentities($row['Onomateponumo'], ENT_QUOTES, 'UTF-8') – devpro Oct 06 '16 at 13:45
  • `mysqli_set_charset($connect, "utf8");` after the query is useless. Set `mysqli_query($connect, "SET NAMES 'utf8'");` before query. – MichaEL Oct 06 '16 at 13:51