In addition to setting mysql_set_charset("utf8");
as mentioned in the other answer, you might need to adjust for a few more settings in order to fully guard yourself against broken characters.
Connection
The connection needs to know what charset to expect. Just after creating the connection, specify the charset like this
$con = mysql_connect('localhost','root','');
mysql_set_charset("utf8");
Headers
Setting the charset in both HTML and PHP headers to UTF-8
PHP: header('Content-Type: text/html; charset=utf-8');
(PHP headers has to be placed before any kind output (echo, whitespace, HTML))
HTML: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
(HTML-headers are placed within the <head>
/ </head>
tag)
Database and tables
Your database and all its tables has to be set to UTF-8. Note that charset is not exactly the same as collation (see this post).
You can do that by running the queries below once for each database and tables (for example in phpMyAdmin)
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Should you follow all of the pointers above, chances are your problem will be solved. If not, you can take a look at this StackOverflow post: UTF-8 all the way through.
mysql_*
functions are deprecated since PHP 5.5 (and removed entirely in PHP 7) and you shoud stop using them if you can.
You should choose another API, like mysqli_*
or PDO instead - see choosing an API.