0

OMG I AM SOO SORRY I HAVE WRONG CODE TYPE :D HERE IS AN EDIT

OK I somehow figured out how to import UTF8 characters in MYSQL but when I load them they are not UTF8. And YES I have

<meta charset="UTF-8"/>

Look At this http://prntscr.com/b13xel . First post is OK but its not UTF8 it is from normal chars latin i think. But 2ND post isnt working :/ I have stored with UTF8 Charset in mysql http://prntscr.com/b13y2n (2ND is Test and Test2 if you dont get it xD) . I think I spelled it wrong xD but NVM I think you will understand me.

This is the code:

<div class = "tablatekst">
                <?php
                $novostid = 1;
                while($novostid < 500)
                {
                    $sqlnovosti = mysql_query("SELECT * FROM novosti WHERE ID = $novostid"); 
                    if(mysql_num_rows($sqlnovosti) > 0)
                    {
                        while($red = mysql_fetch_assoc($sqlnovosti))
                        {
                            $nnaslov = $red['Naslov'];
                            $ntekst = $red['Tekst']; 
                        }
                        echo "<h2> $nnaslov </h2>";
                        echo $ntekst;
                        echo "<br><hr><br>";
                    }
                    $novostid = $novostid + 1;
                }
                ?>


            </div>
Ile Popivanov
  • 95
  • 1
  • 1
  • 7
  • 2
    **WARNING**: If you're just learning PHP, please, do not learn the obsolete [`mysql_query`](http://php.net/manual/en/function.mysql-query.php) interface. It's awful and has been removed in PHP 7. A replacement like [PDO is not hard to learn](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/) and a guide like [PHP The Right Way](http://www.phptherightway.com/) helps explain best practices. Make **sure** your user parameters are [properly escaped](http://bobby-tables.com/php) or you will end up with severe [SQL injection bugs](http://bobby-tables.com/). – tadman May 06 '16 at 20:39
  • 1
    Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Sammitch May 06 '16 at 20:41
  • @tadman please do not put down sql in my opinion its far easier to use then sqli i mean literally went from $row = mysql_fecth_object to $row = mysqli::fetch_results its confusing and unfamiliar to a lot of people and sql is still used way more then new methods –  May 06 '16 at 20:45
  • 1
    @JoséphFlames Don't even start. `mysql_query` is **gone** in PHP 7. This argument is over, the PHP core team decided it was best to get rid of it permanently. Please, stop advocating for something that's dead. It's also full of bugs that will never, ever get fixed. By any measure PDO is easier to do correctly and consistently because it has very good support for **prepared statements** and these are a must-have in any database layer. – tadman May 06 '16 at 20:50
  • LOL NVM :P :/ xD :3 WTF? I thought this forum was about encoding of natural languages in computers, not about cryptic thumb chatter. – Rick James May 07 '16 at 04:36
  • @tadman going to PHP 7 without sql is like going from IOS 8.1.3 to IOS 9 –  May 07 '16 at 22:53
  • You have a problem, take it up with the PHP core team and not me. They rarely remove things, backwards compatibility is a concern for them, but as that interface is the source of so many problems even they decided it's better off dead. PHP still has tons of SQL support, MySQL included, just not the `mysql_query` function or its associated other methods. Use PDO or an ORM. Stop trying to promote this terrible, ancient interface. There really is *nothing* to love about it. – tadman May 08 '16 at 00:18

2 Answers2

1

Put this before your while:

mysql_query('SET NAMES utf8');

However, I strongly recommend you to migrate to mysqli

Mojtaba
  • 4,852
  • 5
  • 21
  • 38
0

What are the content-type headers set to in your PHP script?

https://stackoverflow.com/a/4279294/6275228

Use header to modify the HTTP header:

header('Content-Type: text/html; charset=utf-8');

Note to call this function before any output has been sent to the client. Otherwise the header has been sent too and you obviously can’t change it any more. You can check that with headers_sent. See the manual page of header for more information.

Community
  • 1
  • 1
Technidev
  • 96
  • 1
  • 4
  • I have charset but I coped style line xD I did edited and I fixed it thanks to Mojtaba – Ile Popivanov May 06 '16 at 20:44
  • @IlePopivanov, good to hear you fixed. Please select the correct answer. So, no more developer spends time to open this post. – Mojtaba May 06 '16 at 20:51
  • @IlePopivanov it's important to set the right charset at both client and server side. Keep that in mind next time. – Technidev May 06 '16 at 22:17