Good afternoon, the first time I encountered such a problem! On a local Denver I try to learn how to write in php, everything would be fine, only the encoding in some mysterious way after a couple of passes through the cycles began to change into diamonds! The page is designed as it should be, all the meta, all the markup, utf-8 is written everywhere, the files are also saved in this format, and the base also writes to utf-8. And I tried it on another PC, the same thing ...

<?php @session_start(); $host="localhost"; /*Имя сервера*/ $user="root"; /*Имя пользователя*/ $password=""; /*Пароль пользователя*/ $db="wash"; /*Имя базы данных*/ mysql_connect($host, $user, $password) or die("MySQL сервер недоступен!".mysql_error()); /*Подключение к серверу*/ mysql_select_db($db) or die("Нет соединения с БД".mysql_error()); /*Подключение к базе данных на сервере*/ mysql_query("SET NAMES utf8"); setlocale (LC_ALL, "ru_RU.UTF-8"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <meta http-equiv="Content-Type" content="text/html/php"; charset="utf8"> <meta http-equiv="Cache-Control" content="no-cache"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript" src="js/select.js"></script> <script type="text/javascript" src="js/search.js"></script> <script type="text/javascript" src="js/main.js"></script> <link rel="stylesheet" type="text/css" href="css/search.css"> <link rel="stylesheet" type="text/css" href="css/main.css"> <link rel="stylesheet" type="text/css" href="css/tabl.css"> 

  • In your example, you twice inserted mysql_connect ($ host, $ user, $ password); imprint? - Arsen
  • Indeed, only this did not affect anything ( - Dimastik86
  • double connection and will not affect the encoding) did you check my answer? - Arsen
  • Of course, and it’s interesting that the words are not completely replaced, I tried to delete new ones from the base, write down, the difference is zero Array ([0] => Dry mist # 3 [1] => 1 Brasive polishing # 2 [2] => Liquid glass # 3 [4] => Body washing including thresholds and purging # 1 [ ] => Array ([price] => 0 [vol] => 0) [7] => Array ([price] => 7 [vol ] => 1) [3] => Array ([price] => 3 [vol] => 1)) - Dimastik86
  • In the database, see what is really saved. And it's time to give up on mysql_ functions. This extension is deprecated from version 5.5, and in PHP 7 it is no longer. - Visman

2 answers 2

Try to explicitly set the encoding when connecting to the database:

 $ con = mysql_connect ($ host, $ user, $ password) or die ("Error" .mysql_error ()); 
 mysql_set_charset ($ con, "utf8");
 ........                                    

  • only error received Warning: mysqli_set_charset () expects parameter 1 to be given, resource given in Z: \ home \ localhost \ www \ Wash \ adm \ connect.php on line 8 - Dimastik86
  • Yes, I inertia recorded the mysqli connection - and you have mysql - Arsen
  • check again now - Arsen
  • the same garbage, wrote like this $ con = mysql_connect ($ host, $ user, $ password) or die ("MySQL server is unavailable!". mysql_error ()); / * Connection to server * / mysql_set_charset ($ con, "utf8"); - Dimastik86
  • Ie sql error disappeared but the encoding did not help? - Arsen

the error disappears when I remove the cycle

for ($ i = 0; $ i <count ($ mv_today); $ i ++)

 for ($i=0; $i < count($mv_today); $i++) { foreach ($mv_today[$i] as $key => $value) { if(!isset($tmp[$key])) { $tmp[$key] = $value; } else { $tmp[$key]['vol'] = $tmp[$key]['vol'] + $value['vol']; $tmp[$key]['price'] = $tmp[$key]['price'] + $value['price']; } } }