I have problems with UTF-8 encoding in MySQL DB. I use HTML form to insert data in MySQL DB and PHP code to represent the data from DB. When I insert string "ąčęėįšųū"
using HTML form, I see such “Ä…Äęėįšųū”
symbols in DB in PHPMyAdmin. I don’t have problem with data representation on the WEB, the string “Ä…Äęėįšųū”
is represented trough select function as "ąčęėįšųū".
My goal is to store data "ąčęėįšųū"
not “Ä…Äęėįšųū”
. Do you know how to solve this problem?
MySQL setting > my.ini
init-connect=SET NAMES
utf8 collation_server=utf8_unicode_ci
character_set_server=utf8
DB settings:
Database Collation > utf8_general_ci
Table Collation > utf8_general_ci
Field “Title” collation > utf8_general_ci
Apache > php.ini:
default_charset="UTF-8"
HTML form to submit data:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="tournaments-action.php" accept-charset="utf-8">
<p>
<label for="textfield">Text Field:</label>
<input type="text" name="title" id="textfield">
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit">
</p>
</form>
</body>
</html>
PHP form for submiting data:
<?php
include("../config.php");
$title = mysqli_real_escape_string($db, $_REQUEST['title']);
// attempt insert query execution
$sql = "INSERT INTO tournaments (title) VALUES ('$title')";
if(mysqli_query($db, $sql)){
$msg="Records added successfully.";
echo "Loading";
} else{
$msg="ERROR: Could not able to execute $sql. ";
echo "Loading";
}
// close connection
mysqli_close($db);
?>