When I try to insert a utf8 charcter into my mysql web server database (table is also having collation: utf8_general_ci) unknown junk characters are inserted into the db. I'm trying to input this name (ടോണി) in malayalam language into mysql db using an html file and when this value is submitted on the text box and send to the server db, it appears as like this: (ടോണി). I have also added this line in my php file:
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'",$con);
but still no use. The name is in malayalam. But what I get from db is unknown language. How is that happening?? I will show you my php files and html files:
insert.php
<?php
$con=mysqli_connect("localhost","username","password","db_name");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$txt= $_POST['ta']; // get the unicode text from a submit action.
$unicodeText = $txt;
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'",$con);
$cQry= "insert into doc_test (unicodeText) values ('".$unicodeText."')" ;
if(!mysqli_query($con,$cQry))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
This is my html file:
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<form action="insert.php" method="post">
Name: <input type="text" name="ta">
<input type="submit">
</form>
</body>
</html>
when i run this on my server and enter a value in malayalam in the textbox, and press the submit button, the value will be inserted into the mysql db, but it is not the one which I had entered in the textbox. Also there is a warning shown after the value is entered in the db. It is shown below:
PHP Error Message
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/a6001661/public_html/malayalam/insert.php on line 9
1 record added
What is the possible reason for this warning?? Can someone please correct me out. Also suggest the ideas to enter the value in the correct font malayalam in db. Thanks in advance...