#32927 [Opn->Fbk]: inserting UTF-8 string into mysql

From: Date: Tue, 03 May 2005 21:14:04 +0000
Subject: #32927 [Opn->Fbk]: inserting UTF-8 string into mysql
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-78600@lists.php.net to get a copy of this message
ID: 32927 Updated by: iliaa@php.net Reported By: david dot kalosi at spordat dot sk -Status: Open +Status: Feedback Bug Type: *Languages/Translation Operating System: Windows XP SP1 PHP Version: 5CVS-2005-05-03 (dev) New Comment: Pass the input through mysql_real_escape_string(). Previous Comments: ------------------------------------------------------------------------ [2005-05-03 15:39:01] david dot kalosi at spordat dot sk Description: ------------ I have a Mysql database with UTF-8 encoding and i am posting data from web also in UTF-8 encoding. The slovak character "&#269;" is messed up - the results from the database are differ from the input. All other special characters are OK. Reproduce code: --------------- mysql> create table t (x varchar(64)) character set utf8; Query OK, 0 rows affected (0.21 sec) mysql> <script language="php"> header("Content-Type: text/html;charset=UTF-8"); $l_conn = mysql_connect("localhost", "formawww", "formawww"); mysql_select_db("forma", $l_conn); echo "<form name=\"test\" method=\"POST\" action=\"test.php\">"; echo "<input type=\"text\" name=\"str\">"; echo "<input type=\"hidden\" name=\"insert\" value=\"1\">"; echo "<input type=\"submit\"></form>"; if (isset($_REQUEST["insert"])) { $l_insert = mysql_query ("insert into t values ('" . $_REQUEST["str"]."')"); } $l_select = mysql_query("select * from t"); echo "------------------<br>"; while ($l_row = mysql_fetch_assoc($l_select)) { echo $l_row["x"] . "<br>\n"; } </script> Expected result: ---------------- enter the following values into the form &#318;š&#269;&#357;žýáíéúäô and the following output is produces &#318;š&#319;&#357;žýáíéúäô the third character is corrupted. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32927&edit=1

« previous php.bugs (#78600) next »