Answer the question
In order to leave comments, you need to log in
Why does PHP encoding change?
Hello, I ran into a problem that is not clear to me:
I am making a POST request to the server to the test.php file with two parameters: info1, info2
info1 is data for MySQL
info2 is just a string with Russian letters = "Hello"
The test.php file itself
<?php
require_once('data.php');
require 'main_info.php';
$site= $_POST['info1']; //site
$var1 = $_POST['info2']; //var1
if (!empty($site))
{
$link = mysql_connect($MySQL_hostname,$MySQL_username,$MySQL_password);
mysql_select_db($MySQL_databasename);
$query = "SELECT * FROM $MySQL_table WHERE `Site` = '$site'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$var2 = $row['Title'];
echo $var1 .";" .$var2;
}
else
{
echo "ERR";
}
?>
Answer the question
In order to leave comments, you need to log in
The problem is obviously that you have two encodings mixed up. The browser usually tries to determine the encoding automatically, so in the second case UTF-8 is correctly detected (where "Hello"), and in the first case, another encoding pulls the blanket over itself (probably 1251), and characters encoded in UTF-8 are displayed crookedly . The string "Hello" comes to you in the encoding that is set for the current connection to the database, and it, apparently, is not UTF-8. Put down utf8, for example, in this way. Or change the default encoding in mysqld settings.
By the way, switch to PDO if you are learning data access in PHP. this method is considered obsolete.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question