Malayalam字体字符作为未知字符保存到mysql数据库中

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...

I've decided to make my comment as an answer, for possible future readers and to close the question.


Try placing $con->set_charset("utf8"); right before your query.

That is one method that has worked for many here on SO, where a similar problem was faced.

Also, add error reporting to the top of your file(s) after your opening <?php tag:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Sidenote: You are presently mixing MySQL APIs using mysql_query().

It does not mix with mysqli_* functions inside the same code. It would need to be mysqli_query()


Edit:

"Success.. Adding <meta charset="utf-8"> solved my problem"

as per comments below.

You can get this in three simple steps.

  1. simply set column Collation to "utf8_general_ci" in your database

  2. header('Content-type: text/html; charset=UTF-8'); in your file.

and

  1. $mysqli->set_charset("utf8"); this after mysql connect query.

thats all.