0

I have a setup which loads data from MySQL with PHP and displays it in HTML. It works so far. All the characters are displayed how they should. But when I click a button to refresh a certain part of the site with $.ajax which calls PHP to refresh MySQL data, some characters are displayed as ?-marks, these are the characters which are MySQL data.

HOME

<!doctype html>
<html>
    <head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
        $(function() {
            $("div#click input").live("click", function() {
                $("div#main").load("main.php");
            });
        });
    </script>
    </head>

    <body>
        <div id="main">
        é¨ûåa
        </div>

        <div id="click">
        <input type="button" value="click" onclick="return false;" />
        </div>
    </body>
</html>

Main.php

<?php
$a = mysql_connect('localhost', 'root', '');
mysql_select_db('link', $a);

?>
<div id="main">
ééîüåaa

</div>

<?php
$r = mysql_query("SELECT * from promo;");

while ($row = mysql_fetch_object($r)) {
        $name       = $row->name;
        echo $name;
}
mysql_close($a);
?>

MySQL table:

CREATE TABLE `promo` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL DEFAULT '',
  `link` tinytext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

1 Answer 1

1

try using this call before making your mysql_query

mysql_set_charset("utf8")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.