0

This may seem like a dumb question, I've tried many different solutions with setting the charset but nothing helps. I've got a database with different texts for each day, some of them has got the letters åäö and when loading the page, åäö is just visible as question marks in a black rhombus.

It's working perfectly on my other page but I can't figure out what's wrong.

Here's my code.

$conn = mysqli_connect($servername, $username, $password, $dbname);

                        if (!$conn) {
                            die("Connection failed: " . mysqli_connect_error());
                        }

                        $sql = "SELECT * FROM xxxx WHERE xxx = 'xxxxx'";
                        $result = mysqli_query($conn, $sql);

                        if (mysqli_num_rows($result) > 0) {
                            // output data of each row
                            while($row = mysqli_fetch_assoc($result)) {
                        echo ' 
                        <html>
                        <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                        </head>
                        <body>
                       '.$row["stackinfo"].'<br>
                        '.$row["monday"].'<br>
                        '.$row["tuesday"].'<br>
                       '.$row["wednesday"].'<br>
                      '.$row["thursday"].'<br>
                       '.$row["friday"].'
                       </body>
                       </html>
';
                                }


  } else {
                        echo "0 results";
                        }

                        mysqli_close($conn);

Also, it would be useful if ü, ø, and æ worked as well.

The db uses latin1_swedish_ci.

Thanks in advance!

Update, the full php but without the table name (just for security.)

<?php                       header('Content-Type: text/html; charset=utf-8');
                            define('INCLUDE_CHECK',true);

                            require 'connection file';


                            $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_database);
                            if (!$conn) {
                                die("Connection failed: " . mysqli_connect_error());
                            }

                            $sql = "SELECT * FROM xxx WHERE ClassID = 'xxx'";
                            $result = mysqli_query($conn, $sql);

                            if (mysqli_num_rows($result) > 0) {

                                while($row = mysqli_fetch_assoc($result)) {
                            echo ' 
                            <html>
                            <head>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                            </head>
                            <body>
                            <div class="card">
                            '.$row["stackinfo"].'<br>
                            '.$row["monday"].'<br>
                            '.$row["tuesday"].'<br>
                            '.$row["wednesday"].'<br>
                            '.$row["thursday"].'<br>
                            '.$row["friday"].'
                            </div>
                           </body>
                           </html>
';
                                }
                            } else {
                                echo "0 results";
                            }

                            mysqli_close($conn);
?>
Axel
  • 463
  • 6
  • 19
  • [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze May 06 '15 at 18:40
  • You are really don't want to get help??? the php page you posted and the link you porvided are not the same, because in your php code you havent that `...` output that I see when visit the link. – Alex May 06 '15 at 18:42
  • OP has said nothing about utf8. Why was this marked as a duplicate? – Phil May 06 '15 at 18:43
  • It's the same. That's received from the db too, it's the stackinfo row. But that row are inserted via the ckeditor, which automatically changes letters like å,ä and ö into html and adds html tags as strong before it's added to the db. – Axel May 06 '15 at 18:45
  • *the full php but without the table name* it is not full. the full one must start with ` – Alex May 06 '15 at 18:46
  • Cant write an answer because the question has been incorrectly marked as a duplicate. Since you are working in latin1, you need to change your 1st php line to header('content-type text/html charset=iso-8859-1'); – Phil May 06 '15 at 18:46
  • @Alex, It's at the top left. – Axel May 06 '15 at 18:47
  • @Phil_1984_ did you vist the link https://axelboberg.se/olika_filer/schema_app/ljungarumsskolan/7d/widgets/homework/? there isn't utf-8 yet. so I don't think that the problem is 8859 vs UTF - the problem that header is not set up so far – Alex May 06 '15 at 18:48
  • @Phil_1984_ I tried it but I got an internal server error message from my host so I changed it back. – Axel May 06 '15 at 18:49
  • @Alex I'm not very familiar with headers, I just added the header code to the absolute top in the php document after php – Axel May 06 '15 at 18:50
  • Changing the html meta tag and header to use utf8 is not going to work if the underlying data is still in latin1. Browser will expect utf8, but get latin1. Those black diamonds are invalid utf8 characters. OP could put the data through the utf8_encode function to encode the database data properly for the browser. – Phil May 06 '15 at 18:52
  • @Phil_1984_ I changed just the row monday to utf-8 for test purposes, the other rows are still in latin. Can that be the problem? – Axel May 06 '15 at 18:54
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/77120/discussion-on-question-by-9focuspoints-aao-in-php-and-mysql). – Taryn May 06 '15 at 18:56

0 Answers0